IE逆转了逻辑 [英] IE reverses logic

查看:68
本文介绍了IE逆转了逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然以下代码适用于Firefox和Mozilla,但是/ b $ b IE6会颠倒逻辑(当我点击顶部的是,它会在

底部检查否,反之亦然)。


< form method =" POST">

< p>

< input type = "无线电"命名= QUOT;决定" value =" yes"

onchange =" decisions1 [0] .checked = decision [0] .checked"> yes

< input type ="无线电"命名= QUOT;决定" value =" no"

onchange =" decisions1 [1] .checked = decision [1] .checked"> no。< / font>< / p>

< p>

[...]< / p>

< p>

<输入类型= QUOT;无线电"名称= QUOT; decide1" value =" yes"

onchange =" decision [0] .checked = decision1 [0] .checked"> yes

< input type ="无线电"名称= QUOT; decide1" value =" no"

onchange =" decision [1] .checked = decision1 [1] .checked"> no。< / p>

< ; p>

< input type =" submit" value =" Submit">< input type =" reset"

value =" Reset">< / p>

< / form> ;


请指教。

While the following code works in Firefox and Mozilla,
IE6 reverses the logic (when I click yes on the top it checks no on the
bottom and vice versa).

<form method="POST">
<p>
<input type="radio" name="decide" value="yes"
onchange="decide1[0].checked = decide[0].checked">yes
<input type="radio" name="decide" value="no"
onchange="decide1[1].checked = decide[1].checked">no.</font></p>
<p>
[...]</p>
<p>
<input type="radio" name="decide1" value="yes"
onchange="decide[0].checked = decide1[0].checked">yes
<input type="radio" name="decide1" value="no"
onchange="decide[1].checked = decide1[1].checked">no.</p>
<p>
<input type="submit" value="Submit"><input type="reset"
value="Reset"></p>
</form>

Please advise.

推荐答案

Frank Spade写道:
Frank Spade wrote:
虽然以下代码适用于Firefox和Mozilla,
IE6反转逻辑(当我点击顶部的是,它检查
底部没有,反之亦然)。
While the following code works in Firefox and Mozilla,
IE6 reverses the logic (when I click yes on the top it checks no on the
bottom and vice versa).



[...]


没有进行冗长的解释(其中我可能会得到

更精细的细节错误),原因就是你所用的方式引用了单选按钮的方式被IE和

Mozilla解释。


你也更好关闭使动作发生onclick而不是

onchange,但意见可能会有所不同。


因此修改您的参考文件:


< ; form action ="">

< input type =" radio"命名= QUOT;决定"值= QUOT;是" onclick ="

this.form.decide1 [0] .checked = this.form.decide [0] .checked

">是

< input type =" radio"命名= QUOT;决定"值= [否" onclick ="

this.form.decide1 [1] .checked = this.form.decide [1] .checked

"> no。< br> ;


< input type =" radio"名称= QUOT; decide1"值= QUOT;是" onclick ="

this.form.decide [0] .checked = this.form.decide1 [0] .checked

">是

< input type =" radio"名称= QUOT; decide1"值= [否" onclick ="

this.form.decide [1] .checked = this.form.decide1 [1] .checked

"> no。< br> ;


< input type =" submit" value =" Submit">

< input type =" reset" value ="重置">

< / form>


在Firefox和IE中测试过。


-

Rob


[...]

Without going into lengthy explanations (of which I''d likely get the
finer details wrong anyway), the reason is that the way you have
referenced the radio buttons is interpreted differently by IE and
Mozilla.

You are also better off making the action occur "onclick" rather than
"onchange", but opinions may vary.

Fix your references thusly:

<form action="">
<input type="radio" name="decide" value="yes" onclick="
this.form.decide1[0].checked = this.form.decide[0].checked
">yes
<input type="radio" name="decide" value="no" onclick="
this.form.decide1[1].checked = this.form.decide[1].checked
">no.<br>

<input type="radio" name="decide1" value="yes" onclick="
this.form.decide[0].checked = this.form.decide1[0].checked
">yes
<input type="radio" name="decide1" value="no" onclick="
this.form.decide[1].checked = this.form.decide1[1].checked
">no.<br>

<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

Tested in Firefox and IE.

--
Rob


RobG写道:

< snip>
RobG wrote:
<snip>
无需进行冗长的解释(无论如何我都可能会得到更精细的细节),...
Without going into lengthy explanations (of which I''d
likely get the finer details wrong anyway), ...



< snip>


你不应该担心让他们错误阻止你试图解释更精细的细节。有人会纠正他们,如果你确实犯了错误,那么你的脑海中的细节会更清晰(或者只是更新鲜)。


但是,试图向他人解释b $ b b事物的行为具有相当大的价值。正如Lasse Reichstein Nielsen曾经观察到的那样,你可以确定自己明白了什么,当你可以向别人解释时,他们会理解(假设一个合理的
) />
接受和感知其他)。实际上,它至少需要花费b / b
来尝试对任何事情做出好的解释,但只有在公开场合试图揭露早期版本中的缺陷才会显示出来。 >
(事实错误和未能获得积分的失败)。但值得付出努力,试图以一种很好的学习方式进行教学。


理查德。


<snip>

You shouldn''t let worrying about getting them wrong prevent you from
attempting to explain the finer details. Someone will correct them if
you do make errors, leaving the specifics much clearer (or maybe just
fresher) in your mind.

However, there is considerable value in the act of attempting to explain
things to others. As Lasse Reichstein Nielsen once observed, you can be
certain that you understand something yourself when you can explain it
to others such that they then understand (assuming a reasonably
receptive and perceptive other). Realistically it takes at least a
couple of attempts to formulate a good explanation of anything, but only
attempting that in public will expose the flaws in the early versions
(both factual errors and failures to get points across). But it is worth
the effort, attempting to teach in a great way of learning.

Richard.

Richard Cornford写道:
Richard Cornford wrote:
RobG写道:
< snip>
RobG wrote:
<snip>
没有进行冗长的解释(其中我是'' d
可能会错误地提供更精细的细节),...
< snip>

你不应该担心让他们错误阻止你
试图解释更精细的细节。如果你确实犯了错误,有人会纠正它们,让你的内容更加清晰(或者只是更新鲜)。
Without going into lengthy explanations (of which I''d
likely get the finer details wrong anyway), ...
<snip>

You shouldn''t let worrying about getting them wrong prevent you from
attempting to explain the finer details. Someone will correct them if
you do make errors, leaving the specifics much clearer (or maybe just
fresher) in your mind.




谢谢为了鼓励,我真正的动机是没有时间来b / b $ b b正确调查。所以这里......


进一步的调查显示IE不会触发onchange事件

,直到复选框失去焦点。点击是按钮最初只是设置

复选框来检查。如果你然后点击页面,onchange

会触发,第二个是是。检查。但是,如果你点击否,相反,

第一个是 onchange触发并更改第二个是点击

所以你有一个明显的逻辑逆转。


事实上,所有发生的事情都是第二个不。 onchange还没有被解雇。点击其他地方点击它 - 所以如果你点击

第一个是,它会被检查,第一个否 onchange fires和

第二个no检查。从第一个是开始的改变仍然是

潜伏......


设置第一个是的初始状态在HTML中检查可以创建更加令人困惑的结果。


一旦复选框改变但文本就会触发onzchange

输入,在输入失去焦点之前它的onchange不会被触发(如果

文本已被修改)。


但谁错了?幸运的是,MS似乎已经得到了这个

一个权利。 W3C HTML 4.01规范说:


" onchange事件发生在控件丢失输入

焦点并且其值已经被修改后获得焦点。


Mozilla的行为,虽然更合乎逻辑,但实际上是错误的。使用

复选框导致UI事件被触发也是错误的,但它不是

与任何开放标准不一致我是意识到了(没有那么多的安慰

我很害怕!)


所以事实上我对表格元素的引用是假设的

原因是错误的(感谢理查德),但是...


以指示的方式引用表单元素仍然更好(恕我直言)。


底线是onchange的行为。不一致

跨浏览器或(对于Mozilla而言)

中的不同元素是同一个浏览器,因此不应该依赖它们。


此外,为了达到理想的效果,onclick更加一致

,在这种情况下应该使用。


最后,点击复选框不应该用于触发UI事件

(调出对话框,弹出窗口,更改内容等),但这只是我的意见。

。使用用户*期望*

的按钮或其他UI小部件来导致UI更改 - 最少惊喜原则。

但是,试图向他人解释事物的行为具有相当大的价值。正如Lasse Reichstein Nielsen曾经观察到的那样,当你能够向别人解释它以便他们理解(假设一个合理的接受和敏感的其他人)时,你可以确定你自己理解了什么。



Thanks for the encouragement, my real motive was lack of time to
properly investigate. So here goes...

Further investigation reveals that IE does not fire the onchange event
until the checkbox loses focus. Clicking "yes" initially just sets
that checkbox to checked. If you then click in the page, the onchange
fires and the second "yes" is checked. But, if you click "no" instead,
the first "yes" onchange fires and changes the second "yes" to clicked
so you have an apparent reversal of logic.

In fact, all that''s happened is that the second "no" onchange has not
yet fired. Clicking anywhere else fires it - so if you click back on
the first "yes", it becomes checked, the first "no" onchange fires and
the second "no" is checked. The onchange from the first "yes" is still
lurking....

Setting the initial state of the first "yes" to checked in the HTML can
create even more confusing results.

Mozilla fires the onchange as soon as the checkbox changes BUT on text
inputs, its onchange isn''t fired until the input loses focus (if the
text has been modified).

But who is wrong? As luck would have it, MS seem to have gotten this
one right. The W3C HTML 4.01 spec says:

"The onchange event occurs when a control loses the input
focus and its value has been modified since gaining focus."

Mozilla''s behaviour, whilst more logical, is actually wrong. And using
checkboxes to cause UI events to be fired is also "wrong", but it''s not
at odds with any open standard that I''m aware of (not much solace there
I''m afraid!)

So in fact my presumption regarding references to form elements being
the cause was wrong (thanks Richard), however...

It is still better (IMHO) to refer to form elements the way indicated.

The bottom line is that the behaviour of "onchange" is not consistent
across browsers or (in the case of Mozilla) for different elements in
the same browser and therefore shouldn''t be relied upon.

Further more, to achieve the desired result, onclick is more consistent
and should be used instead in this case.

Lastly, clicks on checkboxes should not be used to fire UI events
(bring up dialogs, popup windows, change content, etc.) but that is
just my opinion. Use buttons or other UI widgets that users *expect*
to cause UI changes - the "least surprise" principle.

However, there is considerable value in the act of attempting to explain
things to others. As Lasse Reichstein Nielsen once observed, you can be
certain that you understand something yourself when you can explain it
to others such that they then understand (assuming a reasonably
receptive and perceptive other).



[...]


是的,因此我根本就潜伏在这里。 :-)

-

Rob


[...]

Yes, hence why I lurk here at all. :-)
--
Rob


这篇关于IE逆转了逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆