mootools_使用MooTools 1.2阻止默认事件操作

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值