在function(e){}函数体中用语句
e.preventDefault();
$('#id').click(function(e) {
e.preventDefault();
});
错在:这个是jquery代码,没有加载jquery库就不能运行,其次,这个return false不对。
js事件绑定方式总结(click事件)
1、HTML onclick事件属性
<button onclick="clickMe(this)">click me</button>
function clickMe(this) {2 alert("click me");3 }
2、JavaScript onclick事件
<button id="button">click me</button>
document.getElementById("button").onclick=clickMe;
3、IE4+<script for>
1 <button id="button1">click me</button>
1 <script for="button1" event="onclick">2 alert("click me");3 </script>
4、IE5/windows attachEvent()方法
<button id="button2">click me</button>
document.getElementById("button2").attachEvent("onclick",clickMe);
5、W3C DOM addEventListener()方法
<button id="button3">click me</button>
document.getElementById("button3").addEventListener("click",clickMe);
最后我用
$("*").click(function(){
var $this = $(this);
alert($this.attr("id"));
return false;
});
测了一下,报的是我上层table的id,好像进不去到我这一单元格,怎么办?
干嘛要用 * ?
追问测试了一下呀,看被单击的是哪个元素
追答你的上层table有绑定点击事件么?如果没有的话,考虑它干嘛。
你给你需要绑定点击事件的元素添加点击事件不就好了么?
是改了之后点击还没效果么?