//<![CDATA[
$(window).load(function() {
$('.n_val').focusout(function() {
alert(this.id);
});
});//]]>
动态生成文本框
buffer += "<tr><td>" + nomen_list.getName() + "</td><td><input type='text' style='width:50px' class='n_val' id=" + nomen_list.getId() + "-" + nomen_list.getCat() + " value=" + nomen_list.getVal() + " /></td></tr>";
我得到了动态文本框,但是 focusout
不适用于动态生成的文本框,而同一页面有一些文本框,这是硬编码的,上面的脚本被触发。
最佳答案
$(window).load(function() {
$(document).on('focusout','.n_val',function() {
alert(this.id);
});
});
您可以使用文本框最接近的父 ID 或类而不是使用文档。我不知道你的 html 布局,因此使用文档。另请参阅 jQuery。
关于javascript - focusout 事件不适用于动态生成的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20419529/