gpt4 book ai didi

javascript - 如何将shiftcheckbox添加到动态生成的复选框?

转载 作者:行者123 更新时间:2023-12-03 09:15:35 24 4
gpt4 key购买 nike

使用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>

为什么不起作用?因为它是动态的?

最佳答案

您需要在附加元素后附加事件,因为您无法委托(delegate)大多数 jquery 插件:

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));

tbody_hosts.find('.shiftCheckbox').shiftcheckbox();
}

关于javascript - 如何将shiftcheckbox添加到动态生成的复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com