Javascript仅在IE中有效,而在另一个浏览器中无效 [英] Javascript is working only in IE but not in Another Browser

查看:81
本文介绍了Javascript仅在IE中有效,而在另一个浏览器中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
在我的项目中,我正在使用以下JavaScript代码验证文本框的值.这段代码可在IE上运行,但不能在其他任何浏览器上运行.任何人都可以帮助我解决这个问题.

这来自文件后面的代码:

Hi Everyone!
In my project I''m validating the value of a textbox using the javascript code below. This code is working on IE, but not any other browser. Can anybody on help me with this issue.

This is from the code behind file:

protected void Page_Load(object sender, EventArgs e)
{
    txtInvNopr.Attributes.Add("onblur", "return validate(this.value)");
}


这是我的JavaScript代码:


This is my javascript code:

function validate(content)
{
    if(isNaN(content)==true)
    {
        alert('Enter Only Numeric Value');
        return false;
    }
    else
        return true;
}



在此先感谢!!



Thanks in advance!

推荐答案

此示例仅通过使用javascript才能起作用.它可以在IE 8/9,FireFox 6.0.2和Chrome 12.xxxx上完美运行.
This example works by only using javascript. It runs absolutely perfect on IE 8/9, FireFox 6.0.2 and Chrome 12.xxxx.
<html>
<head>
<script type="text/javascript">
    function validate(content)
    {
        if(isNaN(content)==true)
        {
            alert('Enter Only Numeric Value');
            return false;
        }
        else
            return true;
    }
</script>
</head>
<body>
<h1>Get attribute test!</h1>
<input id="btnClientId" type="text" value="" name="Whatchamacallit" onblur="return validate(this.value);"/>
<input id="submitIt" type="button" value="Do it!"/>
</body>
</html>



您的代码中肯定有其他地方出了问题.请使用FireBug调试您的页面javascript.

问候,

—MRB



It must be something else that is going wrong in your code. Please use FireBug to debug your pages javascript.

Regards,

—MRB


如果仍然遇到问题,可以使用parseInt()这么长时间,我知道它将在所有浏览器(例如IE5)中都可以使用:

If you are still having trouble, you can so long use parseInt() which i know will work in all browsers (i.e. IE5):

function validate(content)
{
   if(!parseInt(content))
   {
      alert('Enter Only Numeric Value');
      return false;
   }
   else
      return true;
}



祝你好运,
莫尔斯



Goodluck,
Morgs


这篇关于Javascript仅在IE中有效,而在另一个浏览器中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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