本文介绍了获取单元格值时预期的错误函数我...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个带有textbox数量和费率的网格视图,并且当用户输入数量然后对费率文本框的模糊率进行评分时我需要计算 br /> i hve脚本相同,但我得到错误'函数预期'在行JavaScript运行时错误:函数预期 GVRow1.cells(child1).childNodes(0).type function CalAmt(SelectRow){ var GridRow = SelectRow.parentNode.parentNode; var row = SelectRow.parentNode.parentNode; var 数量; var 评分; for ( var child1 = 0 ; child1 < = GridRow.cells.length - 1 ; child1 ++) { alert(GridRow.cells(child1).childNodes( 0 )。type); / / 错误 if (GridRow.cells(child1).childNodes( 0 )。type == text ) { if (GridRow.cells(child1).childNodes( 0 ).id.indexOf( txtqty)> 0 ) {数量= GridRow.cells(child1).childNodes( 0 )。 value ; } if (GridRow.cells(child1).childNodes( 0 ).id.indexOf( txtrate)> 0 ) { Rate = GridRow.cells(child1).childNodes( 0 )。 value ; } if (GridRow.cells(child1).childNodes( 0 )。id.indexOf( txttotal)> 0 ) { GridRow.cells(child1).childNodes( 0 )。 value =数量*速率; } } } } 解决方案 试试吧这个.. < html xmlns = http://www.w3.org/1999/xhtml > ; < head runat = server > < script src = jquery.js.js > < / script > < script 类型 = text / javascript > var calc = function (txt){ var rowid = txt.id.split(' _')[ 2 ]; // GridView1_txtRate_0 var R ate = parseFloat ( document .getElementById(' GridView1_txtRate _' + rowid).value); var 数量= parseFloat ( document .getElementById(' GridView1_txtQty _' + rowid).value); document .getElementById(' GridView1_txtAmt _' + rowid).value = Rate * Qty; } < / script > < / head > < 正文 > < form id = form1 runat = 服务器 > < asp:GridView ID = GridView1 runat = server AutoGenerateColumns = false > < 列 > < asp:TemplateField HeaderText = 评分 > < ItemTemplate > < asp:TextBox ID = txtRate onblur = calc(this) ; runat = server > < / asp:TextBox > < / ItemTemplate > < / asp:TemplateField > < asp:TemplateField HeaderText = 数量 > < ItemTemplate > < asp:TextBox ID = txtQty 的onblur = calc(this); runat = server > < / asp:TextBox > < / ItemTemplate > < / asp:TemplateField > < asp: TemplateField HeaderText = Amt > < ItemTemplate > < asp:TextBox ID = txtAmt runat = 服务器 > < / asp:TextBox > < / ItemTemplate > < / asp:TemplateField > < /列 > < ; / asp:GridView > < / form > < / body > < / html > i have a gridview with textbox qty and rate and amtwhen the user enters qty and then rate on blur of rate textbox i need amt to be calculatedi hve script for the same but i get error 'function expected' in line JavaScript runtime error: Function expectedGVRow1.cells(child1).childNodes(0).typefunction CalAmt(SelectRow) { var GridRow= SelectRow.parentNode.parentNode; var row = SelectRow.parentNode.parentNode; var Qty; var Rate; for (var child1 = 0; child1 <= GridRow.cells.length - 1; child1++) { alert(GridRow.cells(child1).childNodes(0).type);// error if (GridRow.cells(child1).childNodes(0).type == "text") { if (GridRow.cells(child1).childNodes(0).id.indexOf("txtqty") > 0) { Qty = GridRow.cells(child1).childNodes(0).value; } if (GridRow.cells(child1).childNodes(0).id.indexOf("txtrate") > 0) { Rate = GridRow.cells(child1).childNodes(0).value; } if (GridRow.cells(child1).childNodes(0).id.indexOf("txttotal") > 0) { GridRow.cells(child1).childNodes(0).value = Qty * Rate; } } } } 解决方案 Try like this..<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <script src="jquery.js.js"></script> <script type="text/javascript"> var calc = function (txt) { var rowid = txt.id.split('_')[2];// GridView1_txtRate_0 var Rate = parseFloat(document.getElementById('GridView1_txtRate_' + rowid).value); var Qty = parseFloat(document.getElementById('GridView1_txtQty_' + rowid).value); document.getElementById('GridView1_txtAmt_' + rowid).value = Rate * Qty; } </script></head><body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Rate"> <ItemTemplate> <asp:TextBox ID="txtRate" onblur="calc(this);" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Qty"> <ItemTemplate> <asp:TextBox ID="txtQty" onblur="calc(this);" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amt"> <ItemTemplate> <asp:TextBox ID="txtAmt" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form></body></html> 这篇关于获取单元格值时预期的错误函数我...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-11 12:22