1
//<![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不适用于动态生成的文本框,而同一页面有一些文本框,这是硬编码的,上面的脚本被触发。

4

5 回答 5

9
$(window).load(function() {
    $(document).on('focusout','.n_val',function() {
        alert(this.id);
    });
});

您可以使用文本框最接近的父 ID 或类,而不是使用文档。我不知道您的 html 布局,因此使用 document.html。另请参阅 jQuery。

于 2013-12-06T08:48:07.620 回答
2
$(document).on("focusout", ".n_val", function(){
  alert("hi");
});
于 2013-12-06T08:46:02.473 回答
0

尝试这个:

$(document).ready(function() {
    $(document).on('focusout','.n_val', function() {
      alert(this.id);
    });
});
于 2013-12-06T09:26:11.207 回答
0
$(document).on('focusout', '#randmSubstationTable tbody tr td', function () {
    $('#randmSubstationTable tbody tr td')
        .focusout(function(){
            $(this).parent().parent().children().index($(this).parent());
        });
});
于 2020-12-01T05:09:21.667 回答
-1

您应该focusout在每个文本框添加到 DOM 之后调用。在这里您可能调用它太快了(在加载事件中,这可能发生在您添加动态文本框之前)

于 2013-12-06T08:46:17.690 回答