2017-08-14 86 views
-2

jquery创建一个表href。选择一行时,点击脚本将处理所有行。应该只处理点击行。 应该改变什么,所以只选择被点击的行。jquery表href选择所有应该只选择点击行

$("#attachedfiles").append("<tr><td>" + event.name + "</td><td><a href='javascript:;' >[x]</a></td></tr>"); 

$(document).on("click", "#attachedfiles", function()

+3

你的问题尽量不明确,那里的小代码没有很好的格式化,看起来已经完成了一半。你可以编辑这个问题,使其更清晰。 –

+0

编辑您的问题。 –

+0

你想要使用一个类与一个ID。并使用“this”关键字作为点击功能。 – Brian

回答

0

您可以通过使用$(this)

$("#attachedfiles").append("<tr class='someClass'><td>" + "Some Name" + "</td><td><a href='javascript:;' >[x]</a></td></tr>"); 
 
$(document).on("click", "#attachedfiles tr", function() { 
 
    console.log($(this).attr('class')) 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table id="attachedfiles"></table>

+0

这成功了。我曾尝试过课,但从未开除。我读过的所有问题都表明#attachfiles.a就是解决方案。所以它应该是#attachfiles tr。谢谢 – shieldz