【发布时间】:2015-08-12 08:11:36
【问题描述】:
使用this jQuery shiftbox plugin插件或this one。
在 JS 中
for (var hidx in hosts) {
var h = hosts[hidx];
var line_html = '<tr><td><input type="checkbox" class="input shiftCheckbox" value = "'+ hidx +'" data-fullname="'+ h +'"></input></td><td>' + h + '</td> </tr>';
tbody_hosts.append($(line_html));
}
这是动态生成的。
在 HTML 中
<script src="/static/js/jquery.shiftcheckbox.js" type= "text/javascript" ></script>
<script type= "text/javascript" >
$(document).ready (function() {
$('.shiftCheckbox').shiftcheckbox();
});
</script>
为什么它不起作用?因为它是动态的?
【问题讨论】:
-
您在复选框存在之前初始化您的 shiftcheckbox 功能。与其在 document.ready 块中声明它,不如在将动态内容添加到 dom 后找到一种添加方法。还有其他选择 - stackoverflow.com/questions/8690739/…
标签: javascript jquery checkbox shift