mootools 1.11 div 包含选中的复选框
mootools 1.11 如何确定 div 是否包含任何选中的复选框?
使用 $ $$ $E $ES getElements 和 css 选择器尝试了各种变体,如果此 div 不包含复选框,则它不会返回 true
var ticked = $(sId).getElements('[checked=checked]');
if($chk(ticked)){alert('yo');}else{unticked = true;}
how can mootools 1.11 determine if a div contains any checked check boxes?
tried all kinds of variations using $ $$ $E $ES getElements and css selectors, its just not returning true if this div contains no tick boxes
var ticked = $(sId).getElements('[checked=checked]');
if($chk(ticked)){alert('yo');}else{unticked = true;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“checked”是动态分配的 DOM 属性(布尔值),访问该属性仅返回页面加载时存在的值(或使用 setAttribute 时放置的值)。
另外,由于 MooTools 1.11 没有复杂的选择器(不能在 $$ 中直接过滤属性)并且 filterByAttribute 函数仅接受直接字符串比较,这是您唯一(也是最好的!)选项:
注意:我添加 radio 只是为了完整性,无论如何都必须运行过滤器循环来验证检查的状态。
如果您想简化流程并能够重用代码(MooTools 方式),您还可以将选中的过滤器混合到 Elements 中,如下所示:
然后您的选择调用减少为:
"checked" is a dynamically assigned DOM property (which is a boolean), and accessing the attribute only returns the value that was there when the page loaded (or the value you placed when using setAttribute).
Also, as MooTools 1.11 does not have complex selectors (attributes can not be filtered directly within $$) and the filterByAttribute function only accepts direct string comparison, this is your only (and best!) option:
note: I added radio just for completeness, the filter loop would have to be run anyways to verify the checked status.
If you want to simplify the process and be able to reuse the code (the MooTools way), you can also mix-in the checked filter into Elements like this:
and then your selection call is reduced to:
来自文档:
From The Documentation:
对于 1.1
for 1.1