簡體   English   中英

asp.net和javascript

[英]asp.net and javascript

我正在為javascript中的asp文本框分配一個值,如下所示:

var tempStorytxt = document.getElementById("<%=txtStory.ClientID%>");
tempStorytxt.Value = TempValue;
alert(tempStorytxt.Value);

但是當我按以下方式訪問代碼時,txtStory中沒有任何內容

 int StoryId = int.Parse(txtStory.Text);

使用小V作為txtStorytxt.value而不是txtStorytxt.Value

試試這個:

document.getElementById("<%= txtStory.ClientID%>").value = TempValue;

嘗試這個;

<asp:Button ID="btnTest" runat="server" OnClientClick="setVal()" OnClick="btnTest_Click" Text="Test" />

您的js函數;

 function setVal()
 {
   var tempStorytxt = document.getElementById("<%=txtStory.ClientID%>");
   tempStorytxt.setAttribute("value", tempValue);
   alert(tempStorytxt.getAttribute("value"));
 }

並在按鈕單擊事件;

 int StoryId = int.Parse(txtStory.Text);

暫無
暫無

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

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