[英]Uncaught TypeError: undefined is not a function Calling JavaScript Function
I am get the error: Uncaught TypeError: undefined is not a function
when I am trying to call my Javacsript function displayValue()
. 我收到错误: Uncaught TypeError: undefined is not a function
当我尝试调用Javacsript函数displayValue()
时, Uncaught TypeError: undefined is not a function
。
Here is my Javascript code: 这是我的Javascript代码:
var HoC = 0;
var Rate = 0;
function getHoursOrCubes(input, control)
{
HoC = input;
var answer = HoC * Rate;
displayValue(answer);
}
function getRate(input, control)
{
Rate = input;
var answer = HoC * Rate;
displayValue(answer);
}
function displayValue(finalValue) {
var listViewRef = document.getElementById('LV_Tickets');
var elementArray = listViewRef.getElementsByTagName('Label');
alert('this worked.');
for (var i = 0; i < elementArray.length; i++) {
var elementRef = elementArray[i];
elementRef.value = finalValue;
alert(elementRef.value);
}
}
I believe the line that is throwing the error is var elementArray = listViewRef.getElementsByTagName('Label');
我相信var elementArray = listViewRef.getElementsByTagName('Label');
错误的行是var elementArray = listViewRef.getElementsByTagName('Label');
. 。
I have a listview inside a listview and I want to set the value of a label in the nested listview. 我在一个列表视图中有一个列表视图,我想在嵌套的列表视图中设置标签的值。 So that is what I am trying to do here. 这就是我在这里要做的。
Here is my asp code for the ListView I am trying to access: 这是我要访问的ListView的ASP代码:
<asp:ListView ID="LV_Tickets" runat="server" DataSourceID="SQL_Tickets" InsertItemPosition="FirstItem" OnPreRender="LV_Tickets_PreRender" DataKeyNames="TicketNum">
The getHoursOrCubes()
function is called in a nested ListView's insertingitem template: 在嵌套ListView的insertingitem模板中调用getHoursOrCubes()
函数:
<asp:TextBox ID="HoursOrCubesTextBox" runat="server" style="height: 20px; width: 165px;" Text='<%# Bind("HoursOrCubes") %>' onchange="getHoursOrCubes(this.value)" />
var listViewRef = document.getElementById(<%= LV_Tickets.ClientID %>);
var elementArray = listViewRef.getElementsByTagName('Label');
listViewRef
is a nodeList
that means it's a collection of nodes. listViewRef
是一个nodeList
,这意味着它是节点的集合。 To call the function getElementsByTagName
you need a node. 要调用函数getElementsByTagName
您需要一个节点。 I selected the first node in the list by [0]
. 我通过[0]
选择了列表中的第一个节点。 This should return a node on which getElementsByTagName
can be called. 这应该返回一个可以调用getElementsByTagName
的节点。
You're trying to call a function that doesn't exist. 您正在尝试调用一个不存在的函数。
The function getElementsByName
returns an IHTMLElementCollection . 函数getElementsByName
返回一个IHTMLElementCollection 。 Use the tags method of that object to get what you want. 使用该对象的标签方法获取所需的内容。 There is no method for getElementsByTagName
that operates on the IHTMLElementCollection
. 没有在IHTMLElementCollection
上运行的getElementsByTagName
方法。
Instead of 代替
var elementArray = listViewRef.getElementsByTagName('Label');
try 尝试
var elementArray = listViewRef.tags('Label');
That should work for you. 那应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.