簡體   English   中英

如何在ASP.NET webform上使用javascript設置文本框的值

[英]How to set the value of a text box with javascript on an ASP.NET webform

所以在表格中我有以下控件:

<asp:TextBox runat="server" ID="monthlyAmount" ClientIDMode="Static"/>

ClientIDMode靜態是因為正在使用母版頁。

然后我有這個按鈕:

<input type="button" id="calculate" onclick="AutoFillEstimate()" value="Calculate Estimate" />

連接到這個腳本:

<script type="text/javascript">
    function AutoFillEstimate() {
        document.getElementById("monthlyAmount").nodeValue = "test";
    }
</script>

我覺得我只是使用nodeValue而不是我應該使用的東西,但我不知道在哪里尋找這些東西的參考。

如果我理解正確,你只是想設置值,只需使用:

document.getElementById("monthlyAmount").value = "test";

正確的方法是:

document.getElementById("<%= monthlyAmount.ClientID %>").value = "test";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM