我有这个代码:
<ul>
<li class="foo" onclick="alert('Hello')">a</li>
<li class="foo" onclick="alert('Hello')">b</li>
<li class="foo" onclick="alert('Hello')">c</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想alert()在单击<li>文本"a" 时阻止默认操作,我使用此代码:
$(document).on('click','.foo', function(){
if ($(this).text()=='a')
return false;
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用:http://jsfiddle.net/Trk6W/10/
有没有只修改javascript的解决方案?
Updated: I dont wanna remove the attribute onclick because the values of li can change