mootools
Many sweet JavaScript events are trigger by clicking on a link or a submit button. What if you don't want the browser to follow the link? What if you don't want the form to be submitted traditionally? MooTools allows you to prevent the default actions of most elements by using the preventDefault() method.
单击链接或提交按钮会触发许多甜蜜JavaScript事件。 如果您不希望浏览器跟随链接怎么办? 如果您不希望按传统方式提交表单怎么办? MooTools允许您通过使用preventDefault()方法来防止大多数元素的默认操作。
样本XHTML (The Sample XHTML)
<p><a href="http://scriptandstyle.com" class="prevent">ScriptAndStyle.com</a></p>
<p><input type="checkbox" class="prevent" /></p>
<p><input type="submit" class="prevent" value="Submit Form" /></p>
The action of any element with the prevent class will be nullified upon click.
单击时,任何带有prevent类的元素的操作都将无效。
MooTools 1.2代码 (The MooTools 1.2 Code)
window.addEvent('domready', function() {
$each($$('.prevent'),function(el) {
el.addEvent('click',function(event) {
event.preventDefault();
});
});
});
You can also prevent the browser from allowing image dragging! I did, however, notice that this function did not work correctly on a radio input.
您还可以防止浏览器允许图像拖动 ! 但是,我确实注意到此功能在无线电输入上无法正常工作。
翻译自: https://davidwalsh.name/prevent-default-event-actions-mootools-12
mootools