Javascript jQuery单击动态添加的元素

Javascript jQuery单击动态添加的元素,javascript,jquery,html,onclick,Javascript,Jquery,Html,Onclick,我使用jQuery创建了一个HTML表,我想单击第二行中的第一个链接。 生成的HTML如下所示 <tr><td>4</td><td>text</td></tr> <tr id="xrow22" class="xrow"><td colspan="2"><a>0</a><a>1</a></td></tr> 当我尝试从另一个函数调用

我使用jQuery创建了一个HTML表,我想单击第二行中的第一个链接。 生成的HTML如下所示

<tr><td>4</td><td>text</td></tr>
<tr id="xrow22" class="xrow"><td colspan="2"><a>0</a><a>1</a></td></tr>
当我尝试从另一个函数调用此函数时,它不起作用。我使用alert查看了一些值,令人惊讶的是下面的代码警报(第二个值应该是0)

可以使用$().live()函数代替$().on()函数。基本上,当您创建新元素时,jquery不会重新运行并将click-even附加到它。

当我使用
$(this).next().children('td:first child').children('a:first child').text()时我得到了预期的结果。

当我在其中一处或两处更改代码时,代码将完全停止工作
$('table').on('click', '[id^=xrow] a', function(){ ...
<a>0</a><a>1</a>,,[object Object]
$('table').on('click', 'tr:not(.xrow)', function(e){
  $(this).next().children('td:first-child a:first-child').click();
  alert($(this).next().children('td:first-child').html() +','+ $(this).next().children('td:first-child a:first-child').text() +','+ $(this).next().children('td:first-child a:first-child'));
});