Rav*_*avi 1 javascript jquery textbox jquery-focusout
//<![CDATA[
$(window).load(function() {
$('.n_val').focusout(function() {
alert(this.id);
});
});//]]>
Run Code Online (Sandbox Code Playgroud)
动态生成文本框
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>";
Run Code Online (Sandbox Code Playgroud)
我focusout动态生成文本框,但不适用于动态生成的文本框,而同一页面有一些文本框,这是硬编码的,上面的脚本被触发.
$(window).load(function() {
$(document).on('focusout','.n_val',function() {
alert(this.id);
});
});
Run Code Online (Sandbox Code Playgroud)
您可以使用文本框中最接近的父ID或类,而不是使用文档.我不知道你的html布局,因此使用文档.另见jQuery.