我有一个简单的列表,就像这样:
<ul id="large_box_custom_list">
<li id="8" class="large_box">Item 1</li>
<li id="13" class="large_box">Item 2</li>
</ul>
然后我有一个像这样的jQuery函数:
$(function() {
$('li.large_box').css('cursor', 'pointer')
.click(function() {
var show_id = $(this).val();
alert(show_id);
});
});
当我点击列表项时,我的警告框显示的是0,而我期望的值应该是8或13。
this.id
就足够了。请参见其他答案中的评论。 - Matt Ball