event.preventDefault()

event.preventDefault()是通知浏览器不要执行与事件关联的默认动作。,比如document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);来阻止在手机上的滚动,但是阻止后还能再激活吗?

 

1、

取消绑定事件,然后再重写一个绑定事件
比如:
$("a").click(function() {event.preventDefault()}).off('click').click(function() {console.log("OK")});
依然可以打开新窗口。
2、
在 touchstart 事件中绑定 touchmove
在 touchend 中解除 touchmove 绑定即可
$("#id").on(' touchstart',function(){
$("#id").on('touchmove',function(event) {
event.preventDefault();

}, false);

})
$("#id").on(' touchend',function(){
$("#id").unbind('touchmove');

})

3、

用$("body").bind("touchmove",function(event){event.preventDefault;//code});取消了body的拖动事件。

恢复这个拖动事件只要$("body").unbind("touchmove");

非常实用。

4、
$("#id").on('touchmove',function(event) { event.preventDefault(); }, false);
$("#id").unbind('touchmove');
5、
document.addEventListener('touchmove', function(e){bodyScroll(e)}, false);这样就可以了
 
 
 
posted @ 2016-12-11 07:27  沐少白  阅读(896)  评论(0)    收藏  举报