Javascript在IE中不起作用 [英] Javascript doesn't work in IE

查看:94
本文介绍了Javascript在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的页面上有一个javascript,它在IE 8或9以外的所有浏览器中都可以正常工作(在其他版本上未选中).

经过一番尝试和错误后,我发现它似乎是由于与requredfieldValidator冲突引起的,就像我删除requredfieldvalidator且脚本运行正常时一样.这是我的示例代码.

(我已经使用了母版页)

Hi all,

I have a javascript on my page which works fine in all the browsers except IE 8 or 9 (Haven''t checked on other versions.).

After some trial and errors I have found that it appears to be caused by a conflict with the requredfieldValidator as when I removed requredfieldvalidator and script runs OK. Here is my sample code.

(I have used master page)

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">



    function SetStandards(Conducted, Standard, TargetControl) {

        
        TargetControl.value = Number((Number(Standard.value) / Number(Conducted.value) * 100 * 10) / 10).toFixed(1);

        if (isNaN(TargetControl.value) == true) {
            TargetControl.value = '';
        }

        if (TargetControl.value > 100) {
            alert('Some error message.');
            Standard.focus();
        };

    };
</script>

<asp:TextBox ID="txtTecQua0" runat="server" style="text-align:right"

                onBlur="SetStandards(ctl00_ContentPlaceHolder1_txtTecQua0,ctl00_ContentPlaceHolder1_txtTecQua1,ctl00_ContentPlaceHolder1_txtTecQua2);"

                onFocus="GetHelpText('The number of residual chlorine tests refers to routine tests in the distribution network only!  Tests at the treatment plant shall not be included here.')"

                onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"

                    ControlToValidate="txtTecQua0"

                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:TextBox ID="txtTecQua1" runat="server" style="text-align:right"

                onBlur="SetStandards(ctl00_ContentPlaceHolder1_txtTecQua0,ctl00_ContentPlaceHolder1_txtTecQua1,ctl00_ContentPlaceHolder1_txtTecQua2);"

                onFocus = "GetHelpText('No. of residual chlorine tests which were in compliance with the relevant standards')"

                onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"

                    ControlToValidate="txtTecQua1"

                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:TextBox ID="txtTecQua2" runat="server" style="text-align:right" CssClass="DisplayTextbox"



                    onFocus ="GetHelpText('Percentage of residual chlorine tests in compliance with relevant standards. Value is calculated on the basis of reported no. of tests conducted and no. of tests in compliance with relevant standards.')"

                    TabIndex="-1"

                    onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server"

                    ControlToValidate="txtTecQua2"

                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:Button ID="btnCheck" runat="server" Text="Check" ValidationGroup="check" />
                <asp:Button ID="btnSave" runat="server" Text="Save" />

</asp:Content>



有什么建议吗?



Any advice please??

Thanks in advance.

推荐答案

可能会出现问题,因为验证程序维护onblur事件的匿名函数,在该事件中,它无法控制所发送的参数..

尝试通过不带参数的功能...


problem may occurs coz validators maintains anonymous function for onblur event in which its not able to get control which ur sending in parameters..

try by making function without params...
i.e.

function SetStandards() {
       var Conducted = document.getElementById("<%= txtTecQua0.ClientID %>");

       var Standard = document.getElementById("<%= txtTecQua1.ClientID %>");
       var TargetControl = document.getElementById("<%= txtTecQua2.ClientID %>");

       TargetControl.value = Number((Number(Standard.value) / Number(Conducted.value) * 100 * 10) / 10).toFixed(1);

       if (isNaN(TargetControl.value) == true) {
           TargetControl.value = '''';
       }

       if (TargetControl.value > 100) {
           alert(''Some error message.'');
           Standard.focus();
       };

   };



然后像
那样模糊



and call it on blur like

onblur="SetStandards();"



希望对您有帮助. :-)



hope it will help you. :-)


这篇关于Javascript在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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