gpt4 book ai didi

javascript - 为什么在 Ajax 中从 Label 读取值不起作用

转载 作者:行者123 更新时间:2023-12-02 19:35:13 36 4
gpt4 key购买 nike

我正在尝试使用 Ajax 从 Label(asp) 读取值。但我总是得不到定义:|

我的代码是:

function NIS2USD() {
var from = document.getElementById("NIS").value;
var to = document.getElementById("USD").value;
var amount = document.getElementById("totalAmountLabel").value;
request = new XMLHttpRequest();
request.onreadystatechange = ProcessResponse;
request.open("GET", "Convert.aspx?from=" + num1 + "&to=" + num2 + "&amount=" + amount, true);
request.send();
}
function USD2NIS() {
var from = document.getElementById("USD").value;
var to = document.getElementById("NIS").value;
var amount = document.getElementById("totalAmountLabel").value;
request = new XMLHttpRequest();
request.onreadystatechange = ProcessResponse;
request.open("GET", "Convert.aspx?from=" + num1 + "&to=" + num2 + "&amount="+amount, true);
request.send();
}
function ProcessResponse() {
if (request.readyState == 4 && request.status == 200) {
document.getElementById("totalAmountLabel").innerHTML = request.responseText;
}
}

我的标签定义是:

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

为什么我总是遇到undef?

最佳答案

尝试此操作来获取标签的客户端 ID。

var amount = document.getElementById("<%=totalAmountLabel.ClientID%>").innerHTML;

关于javascript - 为什么在 Ajax 中从 Label 读取值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998117/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com