我试图将所有原始和附加元素作为日期选择器,但只有原始作品
我尝试了这段代码,但是下一行输入看起来像普通输入而不是jquery datepicker希望你能找到解决方案谢谢。
这是我的代码。
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
$(document).ready(function(){
$(".inputdate").datepicker({
});
$(".samplebtn").click(function(){
$(".samplediv").append("<input class='inputdate' type='text' name='date'>");
});
});
</script>
<body>
<div class="samplediv">
<input class="inputdate" type="text" name="date">
</div>
<button class="samplebtn">Add</button>
</body>
</html>
绑定动态项后重新初始化日期选择器。
$(".samplebtn").click(function() {
$(".samplediv").append("<input class='inputdate' type='text' name='date'>");
$('.samplediv').find(".inputdate").datepicker({
});
});
你应该将.datepicker()
附加到那些新元素上。试试这个.append()
脚本:
$(".samplediv")
.append("<input class='inputdate' type='text' name='date'>")
.promise()
.done(function() {
$(this).find('.inputdate').datepicker({ ... });
});
希望这有帮助。 :d