[英]Resetting textbox text via javascript
function clickButton(e, buttonid)
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
if (evt.keyCode == 13) {
bt.click();
return false;
}
}
}
txtChatMessage.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSendChat.ClientID + "')");
此函數是在文件后面的代碼中設置的屬性。 單擊按鈕后,如何重置文本框中的文本
您可以這樣做,方法是通過using this
傳遞代碼后的文本字段,並將其value to empty string
setting
value to empty string
javascript中的value to empty string
在后面的代碼中
txtChatMessage.Attributes.Add("onkeypress", "return clickButton(this, event,'" + btnSendChat.ClientID + "')");
在JavaScript中
function clickButton(txt, e, buttonid){
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
if (evt.keyCode == 13) {
bt.click();
txt.value = "";
return false;
}
上面的代碼將覆蓋文本框的現有值。 要保存它供以后使用,我們可以使用隱藏字段
在html中
<asp:hidden id="hdnText" runat="server" >
在JavaScript中
function clickButton(txt, e, buttonid){
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
if (evt.keyCode == 13) {
bt.click();
document.getElementById('<%= hdnText.ClientID %>').value = txt.value;
return false;
}
在后面的代碼中
發送文本字段到javascript函數
txtChatMessage.Attributes.Add("onkeypress", "return clickButton(this, event,'" + btnSendChat.ClientID + "')");
從隱藏字段中獲取文本框的價值
string textBoxValue = hdnText.Value;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.