【发布时间】:2010-09-18 09:42:25
【问题描述】:
查看许多论坛,这似乎是解决方案,但是,它似乎对我不起作用:
function update() {
alert("hello world");
var test = document.getElementById("<%=InCL.ClientID%>").value;
alert(test);
}
而asp/html是:
<asp:TextBox ID="InCL" runat="server" Text="" value="" onchange="update()"></asp:TextBox>
似乎我缺少一些简单的东西?我还尝试在
中使用单引号更改时会弹出“hello world”警报,但不用于测试...
使用 asp.net 3.5、FF、母版页等...
谢谢。
编辑
所以我将其更改为使用 this.value 并且有效,但仍然没有解决如何通过 id 获取它的方法?
作品:
<asp:TextBox ID="InCL" runat="server" Text="" value="1" onchange="update(this.value)"></asp:TextBox>
与:
function update(x) {
alert(x);
}
【问题讨论】:
-
您的 JavaScript 位于何处?在aspx页面?
-
您能否从浏览器“查看源代码”,并确认
document.getElementById()中的id与文本框的id匹配? -
@Russ Cam:它在外部 .js 中 - 添加在母版页中 - 并且确实有效当你好世界弹出时。
-
@Daniel Vassallo:在 html 中,id 是一个奇怪的动态 id,我也匹配它吗?我在哪里可以看到 document.getElementById() 中的 id 变成了什么?
-
@Greg:是的,它应该是动态的。例如:
document.getElementById('ctrl_00incl')应与代码中某处的<input type="text" id="ctrl_00incl" />匹配。
标签: javascript asp.net html windows