如何取消绑定调用event.preventDefault()的侦听器(使用jQuery)?

jQuery默认会触发调用preventDefault(),因此默认设置无效。您不能单击复选框,您不能单击链接等


是否可以恢复默认处理程序?


萧十郎
浏览 684回答 3
3回答

慕斯王

它相当简单让我们假设你做类似的事情document.ontouchmove = function(e){ e.preventDefault(); }现在将其恢复为原始状态,请执行以下操作...document.ontouchmove = function(e){ return true; }从这个网站。

心有法竹

无法还原,preventDefault()但是您可以欺骗它:)<div id="t1">Toggle</div><script type="javascript">$('#t1').click(function (e){&nbsp; &nbsp;if($(this).hasClass('prevented')){&nbsp; &nbsp; &nbsp; &nbsp;e.preventDefault();&nbsp; &nbsp; &nbsp; &nbsp;$(this).removeClass('prevented');&nbsp; &nbsp;}else{&nbsp; &nbsp; &nbsp; &nbsp;$(this).addClass('prevented');&nbsp; &nbsp;}});</script>如果您想更进一步,甚至可以使用触发按钮来触发事件。
打开App,查看更多内容
随时随地看视频慕课网APP