访问控制在Javascript / jQuery函数 [英] Accessing controls in Javascript/JQuery functions

查看:172
本文介绍了访问控制在Javascript / jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的Javascript和JQuery一个问题,当我呼吁文本框的的onblur事件的函数它的值乘到其他文本框的另一个价值code正常工作无母版页,但使用主后页我不知道如何当相关控件的ID被传递给函数搜索控制,一个模式的东西使用$([ID $的jQuery访问控件的ID在母版页=测试])给我的错误,相关的code.what我想要做的就是乘2的值'txtquan1'和'txtattherate1'和结果存储在lblamnt1当我点击提交按钮值店'lblamnt1获得消失了,我已经googleit并不能找到除了的EnableViewState =真解决方案;但问题仍然存在于目前我使用文本框的jQuery一样..... plz帮助

在aspx文件code是:

 < ASP:内容ID =内容1ContentPlaceHolderID =头=服务器>     <脚本类型=文/ JavaScript的>
         $(函数(){
            $([类$ = txtreadonly])ATTR('只读','只读')。
         });         功能funAmount(后缀,数量,金额,totalamt){             变种数量=的document.getElementById(后缀+数量).value的;             VAR AMT =的document.getElementById(后缀+量).value的;
             VAR总= parseFloat(数量)* parseFloat(isNaN(AMT)?0:AMT);             的document.getElementById(后缀+ totalamt).innerText = isNaN(总)? 0:总;
             。的document.getElementById('ddltaxtype')选项[0] = .selected真;
         }         功能funtax(的SelectedValue){
             VAR value22 =的document.getElementById(的SelectedValue).value的             总金额= 0;
             对于(i = 1; I< = 5;我++){                 VAR VAL1 =的document.getElementById('lblamnt'+ I)。价值;
                 如果(val1中!=){
                     总金额=总金额+ parseFloat(VAL1);
                 }
             }             VAR盘=的document.getElementById('txtdiscount')。值
             如果(光盘!=){
                 总金额= parseInt函数(总金额) - parseInt函数(盘);
             }             如果(value22 =='量免税'){                 。的document.getElementById('lbltotalamnt')值=总金额;
                 。的document.getElementById('lbltax')值='0';             }
             否则,如果(value22 =='金额为含税'){                 。的document.getElementById('lbltotalamnt')值=总金额;
                 VAR calTax =(总金额* 100)/ 105;
                 。的document.getElementById('lbltax')值= parseFloat(总金额) - parseFloat(calTax);
             }
             否则,如果(value22 =='金额为应纳税'){                 VAR calTax =(总金额* 5)/ 100;
                 calTax = parseFloat(calTax);
                 。的document.getElementById('lbltax')值= calTax;
                 。的document.getElementById('lbltotalamnt')值=总金额+ calTax;
             }
         }
    < / SCRIPT>    <风格类型=文/ CSS>
        。汽车,STYLE1 {
            宽度:1080px;
        }
        。汽车,节日礼物{
            宽度:253px;
        }
        。汽车,都市风情{
            高度:244px;
            }
    * {
    填充:0;
  / *保证金:0; * /
}
        。汽车,灰色庄重{
            宽度:337px;
        }
        。汽车,都市宝贝{
            宽度:11像素;
        }
    < /风格>
< / ASP:内容>
< ASP:内容ID =内容2ContentPlaceHolderID =ContentPlaceHolder1=服务器>
    < D​​IV>        <表ALIGN =中心类=自动STYLE1>
            &所述; TR>
                &所述; TD>
                    < ASP:标签ID =Label1的=服务器文本=验证custumer细节,并开始计费>< / ASP:标签>
                < / TD>
                &所述; TD>
                    < ASP:标签ID =Label10=服务器文本=单号:>< / ASP:标签>< ASP:标签ID =lblbillno=服务器文本= >< / ASP:标签>
                < / TD>
            < / TR>
            &所述; TR>
                < TD类=自动节日礼物>
                    < ASP:标签ID =Label2的=服务器文本=Custumer名称>< / ASP:标签>
                    < ASP:标签ID =lblcusname=服务器文本=Custumer名称>< / ASP:标签>
                < / TD>
                &所述; TD>
                    < ASP:标签ID =LABEL3=服务器文本=Custumer博士>< / ASP:标签>
                    < ASP:标签ID =lblcusph=服务器文本=Custumer博士>< / ASP:标签>
                < / TD>
            < / TR>
            &所述; TR>
                &所述; TD列跨度=2>
                    < ASP:标签ID =Label11=服务器文本= GT只有20条记录可以同时插入;< / ASP:标签>
                < / TD>
            < / TR>            &所述; TR>
                < TD类=自动都市风情合并单元格=4>
                    <表ID =表1align =left级=自动STYLE1BORDER =1BORDERCOLOR =灰色>
                        &所述; TR>
                            < TD类=自动都市宝贝>
                                序列号
                            < / TD>
                            < TD类=自动灰色庄重>
                                选择数量
                            < / TD>
                            &所述; TD>
                                项目名
                            < / TD>
                            &所述; TD>
                                以速率
                            < / TD>
                            &所述; TD>
                                量
                            < / TD>                        < / TR>                        &所述; TR>
                            < TD类=自动都市宝贝>                                < ASP:标签ID =lblserialnumber=服务器文本=1>< / ASP:标签>                            < / TD>
                            &LT; TD类=自动灰色庄重&GT;                                &LT; ASP:文本框ID =txtquan1=服务器 onblur=\"funAmount(this.id.replace('txtatthe1',''),'txtquan1','txtatthe1','lblamnt1')\"></asp:TextBox>                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtitem1=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                 &所述; ASP:文本框ID =txtatthe1=服务器的onblur =funAmount(this.id.replace('txtquan1',''),'txtquan1','txtatthe1','lblamnt1')&GT;&下; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:文本框ID =lblamnt1级=txtreadonly=服务器文本=&GT;&LT; / ASP:文本框&GT;
                            &LT; / TD&GT;                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                                &LT; ASP:标签ID =Label4=服务器文本=2&GT;&LT; / ASP:标签&gt;                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;                                &LT; ASP:文本框ID =txtquan2=服务器 onblur=\"funAmount(this.id.replace('txtatthe2',''),'txtquan2','txtatthe2','lblamnt2')\"></asp:TextBox>
                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtitem2=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &所述; ASP:文本框ID =txtatthe2=服务器的onblur =funAmount(this.id.replace('txtquan1',''),'txtquan1','txtatthe1','lblamnt1')&GT;&下; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:文本框ID =lblamnt2级=txtreadonly=服务器文本=&GT;&LT; / ASP:文本框&GT;
                            &LT; / TD&GT;
                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                                &LT; ASP:标签ID =Label5=服务器文本=3&GT;&LT; / ASP:标签&gt;                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;                                &LT; ASP:文本框ID =txtquan3=服务器 onblur=\"funAmount(this.id.replace('txtatthe3',''),'txtquan3','txtatthe3','lblamnt3')\"></asp:TextBox>
                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtitem3=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtatthe3=服务器的onblur =funAmount('txtquan3','txtatthe3','lblamnt3')&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:文本框ID =lblamnt3级=txtreadonly=服务器文本=&GT;&LT; / ASP:文本框&GT;
                            &LT; / TD&GT;
                        &LT; / TR&GT;                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                                &LT; ASP:标签ID =Label7=服务器文本=4&GT;&LT; / ASP:标签&gt;                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;                                &LT; ASP:文本框ID =txtquan4=服务器 onblur=\"funAmount(this.id.replace('txtatthe4',''),'txtquan4','txtatthe4','lblamnt4')\"></asp:TextBox>
                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtitem4=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtatthe4=服务器的onblur =funAmount('txtquan4','txtatthe4','lblamnt4')&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =lblamnt4级=txtreadonly=服务器文本=&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                                &LT; ASP:标签ID =的Label8=服务器文本=5&GT;&LT; / ASP:标签&gt;                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;                                &LT; ASP:文本框ID =txtquan5=服务器 onblur=\"funAmount(this.id.replace('txtatthe5',''),'txtquan5','txtatthe5','lblamnt5')\"></asp:TextBox>
                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtitem5=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtatthe5=服务器的onblur =funAmount('txtquan5','txtatthe5','lblamnt5')&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =lblamnt5级=txtreadonly=服务器文本=&GT;&LT; / ASP:文本框&GT;&LT; NOBR /&GT;                            &LT; / TD&GT;                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;
                                &LT; ASP:占位符ID =PLACEHOLDER1=服务器&GT;&LT; / ASP:占位符&GT;
                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;
                                &LT; ASP:占位符ID =PLACEHOLDER2=服务器&GT;&LT; / ASP:占位符&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:占位符ID =预留位置=服务器&GT;&LT; / ASP:占位符&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:占位符ID =预留位置=服务器&GT;&LT; / ASP:占位符&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:占位符ID =PlaceHolder5=服务器&GT;&LT; / ASP:占位符&GT;
                                 &LT; ASP:按钮的ID =btnnext=服务器文本=新建行的风格=保证金左:6像素WIDTH =59px的OnClick =btnnext_Click/&GT;
                            &LT; / TD&GT;                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:标签ID =Label12=服务器文本=输入的折扣,如果任何&GT;&LT; / ASP:标签&gt;                            &LT; / TD&GT;
                            &所述; TD&GT;                                &LT; ASP:文本框ID =txtdiscount=服务器&GT;&LT; / ASP:文本框&GT;                            &LT; / TD&GT;
                        &LT; / TR&GT;
                        &所述; TR&GT;
                            &LT; TD类=自动都市宝贝&GT;                                &LT; ASP:DropDownList的ID =ddltaxtype=服务器的风格=保证金左:0像素的onblur =funtax('ddltaxtype')WIDTH =92px&GT;&LT; / ASP:DropDownList的&GT;                            &LT; / TD&GT;
                            &LT; TD类=自动灰色庄重&GT;
                                &LT; ASP:DropDownList的ID =ddlsalescomm=服务器的风格=保证金左:0像素WIDTH =159px&GT;&LT; / ASP:DropDownList的&GT;&LT; NOBR /&GT;
                                &LT; ASP:DropDownList的ID =ddlcashmode=服务器的风格=保证金左:0像素&GT;&LT; / ASP:DropDownList的&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:标签ID =Label9=服务器文本=总税款:&GT;&LT; / ASP:标签&gt;&LT;无BR /&GT;
                                &LT; ASP:文本框ID =lbltax级=txtreadonly=服务器文本=0WIDTH =62px&GT;&LT; / ASP:文本框&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;
                                &LT; ASP:标签ID =Label6=服务器文本=合计金额&GT;&LT; / ASP:标签&gt; &LT;无BR /&GT;
                                &LT; ASP:文本框ID =lbltotalamnt级=txtreadonly=服务器文本=0WIDTH =72px&GT;&LT; / ASP:文本框&GT;
                            &LT; / TD&GT;
                            &所述; TD&GT;                    &LT; ASP:按钮的ID =btnsave=​​服务器文本=保存的OnClick =btnsave_Click/&GT;                                &LT; ASP:按钮的ID =btnsaveexit=服务器文本=储存并退出的OnClick =btnsaveexit_ClickWIDTH =79px/&GT;                    &LT; ASP:按钮的ID =btnexit=服务器文本=退出的OnClick =btnexit_Click/&GT;                            &LT; / TD&GT;                        &LT; / TR&GT;                    &LT; /表&gt;
                &LT; / TD&GT;
            &LT; / TR&GT;    &LT; /表&gt;
    &LT; / DIV&GT;
&LT; / ASP:内容&GT;


解决方案

检查该根据您的要求如下:

1,采用的ClientIDMode =在​​页面指令静态。

从funAmount 2.取出后缀,如控件ID不会有母版页编号追加。

 函数funAmount(数量,金额,totalamt){
        变种数量=的document.getElementById(数量).value的;
        VAR AMT =的document.getElementById(量).value的;
        VAR总= parseFloat(数量)* parseFloat(isNaN(AMT)?0:AMT);
        的document.getElementById(totalamt).innerText = isNaN(总)? 0:总;
        。的document.getElementById('ddltaxtype')选项[0] = .selected真;
    }

3.Pass的控件功能appropriately.Eg:

 &LT; ASP:文本框ID =txtquan1=服务器的onblur =funAmount('txtquan1','txtatthe1','lblamnt1')&GT;&LT; / ASP:文本框&GT;
 &LT; ASP:文本框ID =txtatthe1=服务器的onblur =funAmount('txtquan1','txtatthe1','lblamnt1')&GT;&LT; / ASP:文本框&GT;

4.Make确保正确的控件ID传递,从code我看到通过了txtatthe2的值不正确。

5.You应该使用网格控件,如果你的行会动态地成长!

i am facing a problem in Javascript and JQuery when i call a function on the "onblur" event of the textbox to multiply its value to another value in other textbox the code works fine without master page but after using master page i don't know how to search for the control when the id of the associated controls is being passed to the function,and one mode thing accessing the id of the control in the master page by JQuery using $("[id$=test]") gives me the error, the associated code.what i want to do is multiply 2 values 'txtquan1' and 'txtattherate1' and store the result in 'lblamnt1' and when i click on the submit button the value store in 'lblamnt1' get vanished,i have googleit and cant find the solution except Enableviewstate=True; but the problem still remains the same for time being i am using jquery on textbox.....plz help

code in aspx file is:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

     <script type="text/javascript">
         $(function () {
            $("[class$=txtreadonly]").attr('readonly', 'readonly');
         });

         function funAmount(suffix, quantity, amount, totalamt) {

             var qty = document.getElementById(suffix + quantity).value;

             var amt = document.getElementById(suffix + amount).value;
             var total = parseFloat(qty) * parseFloat(isNaN(amt) ? 0 : amt);

             document.getElementById(suffix + totalamt).innerText = isNaN(total) ? 0 : total;
             document.getElementById('ddltaxtype').options[0].selected = "true";
         }

         function funtax(selectedvalue) {
             var value22 = document.getElementById(selectedvalue).value

             totalamount = 0;
             for (i = 1; i <= 5; i++) {

                 var val1 = document.getElementById('lblamnt' + i).value;
                 if (val1 != "") {
                     totalamount = totalamount + parseFloat(val1);
                 }
             }

             var disc = document.getElementById('txtdiscount').value
             if (disc != "") {
                 totalamount = parseInt(totalamount) - parseInt(disc);
             }

             if (value22 == 'amount is tax Free') {

                 document.getElementById('lbltotalamnt').value = totalamount;
                 document.getElementById('lbltax').value = '0';

             }
             else if (value22 == 'amount is inclusive of tax') {

                 document.getElementById('lbltotalamnt').value = totalamount;
                 var calTax = (totalamount * 100) / 105;
                 document.getElementById('lbltax').value = parseFloat(totalamount) - parseFloat(calTax);
             }
             else if (value22 == 'amount is taxable') {

                 var calTax = (totalamount * 5) / 100;
                 calTax = parseFloat(calTax);
                 document.getElementById('lbltax').value = calTax;
                 document.getElementById('lbltotalamnt').value = totalamount + calTax;
             }
         }
    </script>

    <style type="text/css">
        .auto-style1 {
            width: 1080px;
        }
        .auto-style3 {
            width: 253px;
        }
        .auto-style4 {
            height: 244px;
            }
    * {
    padding:0;
  /*  margin:0;   */
}
        .auto-style6 {
            width: 337px;
        }
        .auto-style7 {
            width: 11px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">




    <div>

        <table align="center" class="auto-style1">
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Verify the custumer details and start billing"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="Label10" runat="server" Text="Bill Number : "></asp:Label><asp:Label ID="lblbillno" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="auto-style3">
                    <asp:Label ID="Label2" runat="server" Text="Custumer Name"></asp:Label>
                    <asp:Label ID="lblcusname" runat="server" Text="Custumer Name"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="Custumer Ph"></asp:Label>
                    <asp:Label ID="lblcusph" runat="server" Text="Custumer Ph"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Label ID="Label11" runat="server" Text="Only 20 records can be inserted at a time"></asp:Label>
                </td>
            </tr>

            <tr>
                <td class="auto-style4" colspan="4">
                    <table id="table1" align="left" class="auto-style1" border="1" bordercolor="grey">
                        <tr>
                            <td class="auto-style7">
                                Serial Number
                            </td>
                            <td class="auto-style6">
                                Select Quantity
                            </td>
                            <td>
                                Item Name
                            </td>
                            <td>
                                AT The Rate
                            </td>
                            <td>
                                Amount
                            </td>

                        </tr>

                        <tr>
                            <td class="auto-style7">

                                <asp:Label ID="lblserialnumber" runat="server" Text="1"></asp:Label>

                            </td>
                            <td class="auto-style6">

                                <asp:TextBox ID="txtquan1" runat="server" onblur="funAmount(this.id.replace('txtatthe1',''),'txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="txtitem1" runat="server"></asp:TextBox>

                            </td>
                            <td>

                                 <asp:TextBox ID="txtatthe1" runat="server" onblur="funAmount(this.id.replace('txtquan1',''), 'txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>

                            </td>
                            <td>
                                <asp:TextBox ID="lblamnt1" class="txtreadonly" runat="server" Text=""></asp:TextBox>
                            </td>

                        </tr>
                        <tr>
                            <td class="auto-style7">

                                <asp:Label ID="Label4" runat="server" Text="2"></asp:Label>

                            </td>
                            <td class="auto-style6">

                                <asp:TextBox ID="txtquan2" runat="server" onblur="funAmount(this.id.replace('txtatthe2',''),'txtquan2','txtatthe2','lblamnt2')"></asp:TextBox>
                            </td>
                            <td>

                                <asp:TextBox ID="txtitem2" runat="server"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="txtatthe2" runat="server" onblur="funAmount(this.id.replace('txtquan1',''), 'txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>

                            </td>
                            <td>
                                <asp:TextBox ID="lblamnt2" class="txtreadonly" runat="server" Text=""></asp:TextBox>
                            </td>                            
                        </tr>
                        <tr>
                            <td class="auto-style7">

                                <asp:Label ID="Label5" runat="server" Text="3"></asp:Label>

                            </td>
                            <td class="auto-style6">

                                <asp:TextBox ID="txtquan3" runat="server" onblur="funAmount(this.id.replace('txtatthe3',''),'txtquan3','txtatthe3','lblamnt3')"></asp:TextBox>
                            </td>
                            <td>

                                <asp:TextBox ID="txtitem3" runat="server"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="txtatthe3" runat="server" onblur="funAmount('txtquan3','txtatthe3','lblamnt3')"></asp:TextBox>

                            </td>
                            <td>
                                <asp:TextBox ID="lblamnt3" class="txtreadonly" runat="server" Text="" ></asp:TextBox>
                            </td>                            
                        </tr>

                        <tr>
                            <td class="auto-style7">

                                <asp:Label ID="Label7" runat="server" Text="4"></asp:Label>

                            </td>
                            <td class="auto-style6">

                                <asp:TextBox ID="txtquan4" runat="server" onblur="funAmount(this.id.replace('txtatthe4',''),'txtquan4','txtatthe4','lblamnt4')"></asp:TextBox>
                            </td>
                            <td>

                                <asp:TextBox ID="txtitem4" runat="server"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="txtatthe4" runat="server" onblur="funAmount('txtquan4','txtatthe4','lblamnt4')"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="lblamnt4" class="txtreadonly" runat="server" Text="" ></asp:TextBox>

                            </td>

                        </tr>
                        <tr>
                            <td class="auto-style7">

                                <asp:Label ID="Label8" runat="server" Text="5"></asp:Label>

                            </td>
                            <td class="auto-style6">

                                <asp:TextBox ID="txtquan5" runat="server" onblur="funAmount(this.id.replace('txtatthe5',''),'txtquan5','txtatthe5','lblamnt5')"></asp:TextBox>
                            </td>
                            <td>

                                <asp:TextBox ID="txtitem5" runat="server"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="txtatthe5" runat="server" onblur="funAmount('txtquan5','txtatthe5','lblamnt5')"></asp:TextBox>

                            </td>
                            <td>

                                <asp:TextBox ID="lblamnt5" class="txtreadonly" runat="server" Text="" ></asp:TextBox><nobr />

                            </td>

                        </tr>
                        <tr>
                            <td class="auto-style7">
                                <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                            </td>
                            <td class="auto-style6">
                                <asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
                            </td>
                            <td>
                                <asp:PlaceHolder ID="PlaceHolder3" runat="server"></asp:PlaceHolder>
                            </td>
                            <td>
                                <asp:PlaceHolder ID="PlaceHolder4" runat="server"></asp:PlaceHolder>
                            </td>
                            <td>
                                <asp:PlaceHolder ID="PlaceHolder5" runat="server"></asp:PlaceHolder>
                                 <asp:Button ID="btnnext" runat="server" Text="New Row" style="margin-left: 6px" Width="59px" OnClick="btnnext_Click" />
                            </td>

                        </tr>
                        <tr>
                            <td class="auto-style7">

                            </td>
                            <td>

                            </td>
                            <td>

                            </td>
                            <td>

                                <asp:Label ID="Label12" runat="server" Text="Enter the discount if any"></asp:Label>

                            </td>
                            <td>

                                <asp:TextBox ID="txtdiscount" runat="server" ></asp:TextBox>

                            </td>
                        </tr>
                        <tr>
                            <td class="auto-style7">

                                <asp:DropDownList ID="ddltaxtype" runat="server" style="margin-left: 0px"  onblur="funtax('ddltaxtype')"  Width="92px" ></asp:DropDownList>

                            </td>
                            <td class="auto-style6">
                                <asp:DropDownList ID="ddlsalescomm" runat="server" style="margin-left: 0px" Width="159px" ></asp:DropDownList><nobr />
                                <asp:DropDownList ID="ddlcashmode" runat="server" style="margin-left: 0px" ></asp:DropDownList>
                            </td>
                            <td>
                                <asp:Label ID="Label9" runat="server" Text="Total Tax : "></asp:Label><no br />
                                <asp:TextBox ID="lbltax" class="txtreadonly" runat="server" Text="0"  Width="62px"></asp:TextBox>
                            </td>
                            <td>
                                <asp:Label ID="Label6" runat="server" Text="Total Amount"></asp:Label> <no br />
                                <asp:TextBox ID="lbltotalamnt" class="txtreadonly" runat="server" Text="0" Width="72px"></asp:TextBox>
                            </td>
                            <td>

                    <asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnsave_Click" />

                                <asp:Button ID="btnsaveexit" runat="server" Text="Save & exit" OnClick="btnsaveexit_Click" Width="79px" />

                    <asp:Button ID="btnexit" runat="server" Text="Exit" OnClick="btnexit_Click" />

                            </td>

                        </tr>

                    </table>
                </td>
            </tr>

    </table>
    </div>


</asp:Content>

解决方案

Check if this works according to your requirement:

1.Use ClientIDMode="Static" in the Page Directive.

2.Remove suffix from the funAmount, as control ids will not have the master page id appended.

        function funAmount(quantity, amount, totalamt) {           
        var qty = document.getElementById(quantity).value;
        var amt = document.getElementById(amount).value;
        var total = parseFloat(qty) * parseFloat(isNaN(amt) ? 0 : amt);
        document.getElementById(totalamt).innerText = isNaN(total) ? 0 : total;
        document.getElementById('ddltaxtype').options[0].selected = "true";
    }

3.Pass the controls to the function appropriately.Eg:

 <asp:TextBox ID="txtquan1" runat="server" onblur="funAmount('txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>
 <asp:TextBox ID="txtatthe1" runat="server" onblur="funAmount('txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>

4.Make sure the correct control ids are passed,from your code i see the value passed for "txtatthe2" is incorrect.

5.You should be using a grid control if your rows are going to grow dynamically!

这篇关于访问控制在Javascript / jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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