onchange的条件
[2010-08-30 11:08:03 --@Javascript]
The onchange event is fired when the element loses the focus and the contents have changed since the last time the element got the focus. To detect when the contents have changed
onchange之后一定有onblur。但onblur之前却不一定有onchange:
onchange的条件之一是"the contents have changed" 即内容改变了,与the last time the element got the focus即最近一次获得焦点的内容作对比。
问题:若对onfocus附加了一个函数例如:
执行函数即改变了elem的value值,在失去焦点时,要对比的值是 函数执行前还是函数执行后?
事实证明这个要对比的值在函数(线程)执行后:the last time the element got the focus,即如果对onfocus附加了函数,该函数的线程执行完成后才叫got the focus,即使这个线程执行了很长事件例如5秒,本来获得焦点这一瞬间的事 也是在5秒之后。
写到一半后,发现自己想复杂了,任保留以上错误分析文字
经过测试,最终总结:
onchange 发生在 手动(不包含代码实现:.value="....")改变内容并失去焦点后 判断内容是否有改变,有则onchang触发。
手没有动键盘,onchange永不触发
onchange之后一定有onblur。但onblur之前却不一定有onchange:
onchange的条件之一是"the contents have changed" 即内容改变了,与the last time the element got the focus即最近一次获得焦点的内容作对比。
问题:若对onfocus附加了一个函数例如:
elem.onfocus=function(){
this.value="focus";
};
this.value="focus";
};
执行函数即改变了elem的value值,在失去焦点时,要对比的值是 函数执行前还是函数执行后?
事实证明这个要对比的值在函数(线程)执行后:the last time the element got the focus,即如果对onfocus附加了函数,该函数的线程执行完成后才叫got the focus,即使这个线程执行了很长事件例如5秒,本来获得焦点这一瞬间的事 也是在5秒之后。
写到一半后,发现自己想复杂了,任保留以上错误分析文字
经过测试,最终总结:
onchange 发生在 手动(不包含代码实现:.value="....")改变内容并失去焦点后 判断内容是否有改变,有则onchang触发。
手没有动键盘,onchange永不触发
本文禁止复制/转载!