我的表格中有以下按钮
<td><Button id="approval_<?php echo $i; ?>" type="submit" class="myclass btn success trr" ><span>Approve</span> </button>
</td>
<td><Button id="approval_<?php // echo $i; ?>" type="submit" class="smyclass btn failed trr" ><span>Deny</span> </button>
</td> 我需要执行onclick操作
像这样的东西
$('.myclass').click(function() {}问题是,我如何判断哪个按钮被点击了?
发布于 2012-06-29 05:19:53
在click函数中,您可以使用$(this)引用对其执行操作的元素。
所以:
$('.myclass').click(function() {
$(this).doStuff();
});快速注意-您将需要缓存$(this)。这样,您可以根据需要多次引用它,但只需执行一次DOM查找。
如下所示:
$('.myclass').click(function() {
var $this = $(this);
$this.doStuff();
$this.doMoreStuff();
});发布于 2012-06-29 05:18:34
您可以检查按钮是否包含具有jQuery函数hasClass的类。
$('.myclass').click(function() {
if($(this).hasClass('success')){
alert("Success!");
}
});关键字this将是您单击的按钮。您可以通过编写$( jQuery )将其包装在jQuery中,这将允许您在其上使用大量方便的a函数。
发布于 2012-06-29 05:21:43
$('.myclass').click(function() {
// In here "this" refers to your element that was clicked.
// You can do whatever you want with it from here.
// If you want to use jQuery make sure to wrap it like $(this)
});我建议看一看jQuery Tutorials,它会解释很多关于jQuery是如何工作的,这将在将来为你节省很多时间
https://stackoverflow.com/questions/11253029
复制相似问题