复选框:以编程方式检查它,触发'onchange'处理程序 [英] Checkbox: programmatically checking it, triggering the 'onchange' handler
问题描述
你好,
我一直在网上寻找解决这个问题的方法:
我创建一组复选框和2个按钮:
- 一个标记为全部
- 另一个标记为无
>
点击全部应该检查所有的复选框,它确实是
(那不是火箭科学;),但''onchange''事件没有得到
触发。
我无法在
clj的档案中找到这个问题的答案(尽管我打赌有),所以任何想法/指针绝对是
欢迎。
我在这里做了一些不合适的事吗?
感谢您的任何信息!
祝你好运,
Arnaud
Hello,
I''ve been looking on the web for a solution to this problem:
I create a set of checkboxes, and 2 buttons:
- one is labeled "All"
- the other is labeled "None"
Clicking "All" is supposed to check all the checkboxes, which it does
(that''s not rocket science ;), but the ''onchange'' event does not get
triggered.
I couldn''t find an answer to this issue in the archives of
c.l.j. (even though I bet there is), so any idea/pointer is absolutely
welcome.
Am I doing something inappropriate here?
Thank you for any info!
Best regards,
Arnaud
推荐答案
遵守KIS规则,
< ;表格>
< input type ="复选框"名称= QUOT; checkIt" />
< input type ="复选框"名称= QUOT; checkIt" />
< input type ="复选框"名称= QUOT; checkIt" />
< input type =" button" value =" Tick All Boxs"的onclick = QUOT; runCheckAll()" />
< / form>
< script type =" text / javascript">
<! -
函数runCheckAll()
{
var changeCheck = document.getElementsByName('' checkIt'');
for(i = 0; i< changeCheck.length; i ++)
{
changeCheck [i] .checked = true;
}
}
// - >
< /脚本>
Observe the rule of KIS,
;-)
<form>
<input type="checkbox" name="checkIt" />
<input type="checkbox" name="checkIt" />
<input type="checkbox" name="checkIt" />
<input type="button" value="Tick All Boxs" onclick="runCheckAll()" />
</form>
<script type="text/javascript">
<!--
function runCheckAll()
{
var changeCheck = document.getElementsByName(''checkIt'');
for(i=0; i<changeCheck.length; i++)
{
changeCheck[i].checked = true;
}
}
//-->
</script>
等等,我没有正确阅读你的帖子,抱歉。
我想您可以设置一个处理程序,以便在没有用户的情况下从脚本触发
更改任何内容。 Waitasec ......
Ah wait, I didn''t read your post properly, sorry.
I think you can set a handler to fire from a script without user
changing anything. Waitasec...
aundro写道:
你好,
我一直在寻找在网上找到解决这个问题的方法:
我创建了一组复选框和2个按钮:
- 一个标记为All
- 另一个标记为None
点击全部应该检查所有复选框,它确实是
(这不是火箭科学;),但是'onchange''事件没有被触发。
也许是因为它没有必要? :-)
< checkbox>有一个顶级用户输入事件:onclick (除了所有
这些onkeypress,onbeforeprint等)
IE有一个名为onpropertychange的新事件。如果你改变复选框状态,将会调用它:
< input type ="复选框"名称= QUOT; CB02" onpropertychange =" myFunction(this)">
FF有一些非常模糊的界面,用于在我的帖子中讨论的以编程方式生成的
事件:
发布者:VK
< http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/2602a35ef4a14ac1/50a2ac2da48b4df3>
但在这种特殊情况下,人工点击似乎没有效果
(没有通过检查此选项)。
我在这里做了一些不合适的事吗?
Hello,
I''ve been looking on the web for a solution to this problem:
I create a set of checkboxes, and 2 buttons:
- one is labeled "All"
- the other is labeled "None"
Clicking "All" is supposed to check all the checkboxes, which it does
(that''s not rocket science ;), but the ''onchange'' event does not get
triggered.
Maybe because it doesn''t have to? :-)
<checkbox> has one top level user input event: "onclick" (besides all
these onkeypress, onbeforeprint etc.)
IE has new event called "onpropertychange" which will be called if you
change the checkbox state:
<input type="checkbox" name="cb02" onpropertychange="myFunction(this)">
FF has some very obscure interface for programmatically generated
events discussed in my post here:
Posted by: VK
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/2602a35ef4a14ac1/50a2ac2da48b4df3>
But in this particular case an "artificial click" seems has no effect
(did not check this option through).
Am I doing something inappropriate here?
你可以用任何你想要的方式做任何事情:-)
我不清楚为什么你需要这种双层方案:1)选择2)
trig onselect事件做其他事情?
为什么不一步一步:
复选框[i] .checked = true ;
someOtherActionWith(checkboxes [i]);
?
You can do whatever you want in any way you want :-)
I am just not clear why you need this two-tier scheme: 1) select 2)
trig onselect event to do something other ?
Why not just do it in one step:
checkboxes[i].checked = true;
someOtherActionWith(checkboxes[i]);
?
这篇关于复选框:以编程方式检查它,触发'onchange'处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!