IM ...jQuery的日期选择在克隆行使用附带的jQuery的日期选择器
new.php
<html>
<table id="testtable">
<tr id="table_row1">
<td><input type="text" name="date[]" class="pickDate"></td>
<td><?php ...some php stuff here...?> </td>
</tr>
</table>
<label onclick="cloneRow('testtable','table_row1')"></label>
</html>
的index.php
<html>
<php
include('new.php')
?>
<script>
$(document).ready(function() {
$('.pickDate').each(function() {
$(this).datepicker({ dateFormat: 'dd.mm.yy' });
});
});
</script>
</html>
的JavaScript功能克隆:
function cloneRow(tablename,rowname) {
var row = document.getElementById(rowname); // find row to copy
var table = document.getElementById(tablename); // find table to append to
var clone = row.cloneNode(true); // copy children too
clone.id = "newID"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
}
所以问题是,在第一行,日期选择器在那里,并工作,但如果我克隆行,克隆的没有datepicker。
我检查了该类是否被克隆过,是的。
我很新的jquery,但没有jQuery的可能不会注意到,有添加一个新的行?
我如何得到这个工作?
我想你必须在cloneRow函数后再次运行.each()方法。 – Aqib1604 2014-10-02 16:46:34
@Aqib1604怎么样? – 2014-10-02 16:53:29
只是复制并粘贴您的$(“。pickDate”)。每个代码是在document.ready下的cloneRow函数的末尾 – Aqib1604 2014-10-02 16:55:51