我正在尝试使用按钮来获取ID $(this).id,但它是未定义的.我究竟做错了什么?谢谢阅读.
编辑:来自jsFiddle的代码示例:
HTML
<button id='remove_button' type='button'>Remove</button>?
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('#remove_button').mouseup(function(){
alert($(this).id);
});?
Run Code Online (Sandbox Code Playgroud)
$(this)
为您提供对jQuery对象的引用.您可以使用像Mario所说的attr()函数,或者甚至只是这样做:
this.id