[英]live validation javascript not running in Internet Explorer
I am trying to use a pre-built javascript library called LiveValidation, that validates a test field as you type in it. 我正在尝试使用名为LiveValidation的预构建javascript库,该库在您键入测试字段时会对其进行验证。 The script is running fine in FireFox, but it's not working in IE at all.
该脚本在FireFox中运行良好,但根本无法在IE中运行。 I went to the website of LiveValidation where it says that it supports IE 6,7,8 (i am using IE7), and I have confirmed that Javascript is enabled.
我访问了LiveValidation网站,该网站说它支持IE 6,7,8(我正在使用IE7),并且我已经确认启用了Javascript。
This is the link to the Javascript files... http://livevalidation.com/download 这是指向Javascript文件的链接... http://livevalidation.com/download
And this is the HTML code where I use the validator... 这是我使用验证器的HTML代码...
<label>First Name<font style="color:#FF0000;">*</font> </label>
<input type="text" value="" name="first_name" id="first_name"/>
<script type="text/javascript">
var f1 = new LiveValidation('first_name');
f1.add(Validate.Presence,{failureMessage: " Please enter username"});
f1.add(Validate.Format,{pattern: /^[a-z\s]+$/i ,failureMessage: " It allows only characters"});
f1.add(Validate.Format,{pattern: /^[a-zA-Z][a-z\s]{0,}$/,failureMessage: " Invalid username"});
f1.add(Validate.Length, { minimum: 4, maximum: 15 } );
</script>
You should probably enclose your validation code in a function, and then call that function whenever the user types into the textfield. 您可能应该将验证代码包含在一个函数中,然后在用户键入文本字段时调用该函数。 For example...
例如...
<script type="text/javascript">
function doValidation(){
var f1 = new LiveValidation('first_name');
f1.add(Validate.Presence,{failureMessage: " Please enter username"});
f1.add(Validate.Format,{pattern: /^[a-z\s]+$/i ,failureMessage: " It allows only characters"});
f1.add(Validate.Format,{pattern: /^[a-zA-Z][a-z\s]{0,}$/,failureMessage: " Invalid username"});
f1.add(Validate.Length, { minimum: 4, maximum: 15 } );
}
</script>
<label>First Name<font style="color:#FF0000;">*</font> </label>
<input type="text" value="" name="first_name" id="first_name" onKeyPress="doValidation()" />
So, every time the user presses a key in the textfield, it will call the doValidation()
and run the LiveValidator
. 因此,每次用户在文本字段中按下一个键时,它将调用
doValidation()
并运行LiveValidator
。 I think that IE is doing the correct thing, and Firefox might just be helping you out by guessing what you were intending to code. 我认为IE做的是正确的事情,而Firefox可能只是通过猜测您打算编写的代码来帮助您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.