mootools弹框_使用MooTools选中所有/无复选框

mootools弹框

There's nothing worse than having to click every checkbox in a list. Why not allow users to click one item and every checkbox becomes checked? Here's how to do just that with MooTools 1.2.

没有比单击列表中的每个复选框更糟糕的了。 为什么不允许用户单击一个项目,并且选中每个复选框? 使用MooTools 1.2的方法如下。

XHTML (The XHTML)


<table>
	<tr>
		<th width="30"><img src="checkboxes/uncheck.jpg" id="ucuc" /></th><th>Title</th>
	</tr>
	<tr>
		<td><input type="checkbox" name="approve[]" class="check-me" value="Braveheart" /></td>
		<td>Braveheart</td>
	</tr>
	<tr>
		<td><input type="checkbox" name="approve[]" class="check-me" value="Gladiator" /></td>
		<td>Gladiator</td>
	</tr>
	<tr>
		<td><input type="checkbox" name="approve[]" class="check-me" value="The Patriot" /></td>
		<td>The Patriot</td>
	</tr>
	<tr>
		<td><input type="checkbox" name="approve[]" class="check-me" value="300" /></td>
		<td>300</td>
	</tr>
</table>


Note the image with the ucuc ID -- that image will be the checkbox trigger.

注意具有ucuc ID的图像-该图像将成为复选框触发器。

CSS (The CSS)

#ucuc	{ cursor:pointer; }

Give the image the pointer cursor for enhanced usability.

为图像提供指针光标以增强可用性。

MooTools 1.2 JavaScript (The MooTools 1.2 JavaScript)


window.addEvent('domready', function() {
	var ucuc = $('ucuc');
	ucuc.addEvent('click', function() {
		if(ucuc.get('rel') == 'yes') {
			do_check = false;
			ucuc.set('src','checkboxes/uncheck.jpg').set('rel','no');
		}
		else {
			do_check = true;
			ucuc.set('src','checkboxes/check.jpg').set('rel','yes');
		}
		$$('.check-me').each(function(el) { el.checked = do_check; });
	});
});


Extremely simple: read in whether to check or uncheck the boxes, take the appropriate action, and swap out the images.

非常简单:阅读是选中还是取消选中这些框,采取适当的措施,然后交换图像。

翻译自: https://davidwalsh.name/check-all-none-checkboxes-using-mootools

mootools弹框

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值