且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

追加使用jQuery新行和输入标签

更新时间:2023-12-03 22:14:40

如果你是在jQuery的1.7+然后用委托来代替。它比老方法更有效。在这里,我监测的表格单元格单击事件表。当事件发生时我加入点击!表格单元格。这既适用于初始表单元格并添加的。

If you are in jQuery 1.7+ then use on or delegate instead. It is more efficient than old methods. Here I monitor the table for click events on table cells. When an event occurs I add clicked! to the table cell. This works for both the initial table cells and added ones.

http://jsfiddle.net/WBxQz/1/

$('#more').change(function(e) {
    for (var i = 0; i < $(this).val(); i++) {
        $('#myTable').append('<tr><td></td></tr>');
    }
});

$('table').on('click', 'td', function() {
    $(this).html('clicked!');
});