[英]How to set the value of a text box with javascript on an ASP.NET webform
so in a form I have the following control: 所以在表格中我有以下控件:
<asp:TextBox runat="server" ID="monthlyAmount" ClientIDMode="Static"/>
The ClientIDMode Static is because a master page is in use. ClientIDMode静态是因为正在使用母版页。
I then have this Button: 然后我有这个按钮:
<input type="button" id="calculate" onclick="AutoFillEstimate()" value="Calculate Estimate" />
Wired to this Script: 连接到这个脚本:
<script type="text/javascript">
function AutoFillEstimate() {
document.getElementById("monthlyAmount").nodeValue = "test";
}
</script>
I feel like I'm just using nodeValue instead of what I should be using, but I have no idea where to look for reference on these things. 我觉得我只是使用nodeValue而不是我应该使用的东西,但我不知道在哪里寻找这些东西的参考。
如果我理解正确,你只是想设置值,只需使用:
document.getElementById("monthlyAmount").value = "test";
正确的方法是:
document.getElementById("<%= monthlyAmount.ClientID %>").value = "test";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.