javascript在chrome&不在ie&火狐 [英] javascript working in chrome & not working in ie & firefox

查看:108
本文介绍了javascript在chrome&不在ie&火狐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码显示文本字段。当它失去焦点(onBlur)时,我正在调用一个函数来验证文本。这在Chrome中运行良好,但在& Firefox浏览器。当我打开它时,即我得到了文本框,但没有调用验证功能。





document.writeln(邮政编码< ;输入类型= \text \name = \postalCode \onBlur = \validateText(); \>< / input>);



如何让它在ie& firefox也是?

I'm using the following code to dispaly a text field. When it lost focus(onBlur), i'm calling a function to validate the text. This is working fine in Chrome but not in ie & firefox. When I open it in ie I got the text box but the validation function was not called.


document.writeln("Postal Code<input type=\"text\" name=\"postalCode\" onBlur=\"validateText();\" ></input>");

How to make it work in ie & firefox too?

推荐答案

这取决于何时你发出相对于的代码当/何时 validateText 定义了函数。请注意,javascript引擎在这些浏览器中并不相同,并且它们使用不同的逻辑处理/解析代码。我可以想象,这个代码甚至在解析函数之前发出。我建议你使用DOM(JQuery可以帮助你),而不是这种过时的方法,并确保将这些函数放在头部而不是内联中 - 并且只在文档readly [ ^ ]:完全加载并解析。
It depends on when you issue that code relative to when/where the validateText function is defined. Be aware, that the javascript engines are not the same across those browsers, and they are processing/parsing the code with different logic. I can imagine, that this code is issued before even the function is parsed. I suggest you use DOM (JQuery can help you considerably), instead of this outdated approach, and be sure to put/or include such functions in the head section and not inline - and create additional element only when the document is readly[^]: completely loaded and parsed.


这篇关于javascript在chrome&amp;不在ie&amp;火狐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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