你可以像这样做,从代码传递文本字段后面using this
和setting
其value to empty string
在JavaScript
在后面的代码
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的乐趣从隐藏字段的文本框的ction
txtChatMessage.Attributes.Add("onkeypress", "return clickButton(this, event,'" + btnSendChat.ClientID + "')");
获得价值
string textBoxValue = hdnText.Value;
我已经尝试设置通过jQuery的价值,但这样做在Mozilla Firefox中一个有趣的现象。文本消息不通过服务器,但空白的消息去服务器 – 2012-08-12 11:36:51
这是它应该怎么做,你不重置在JavaScript,但在服务器上然后。 – Adil 2012-08-12 11:38:32
我已经使用隐藏字段更新了我的答案,以保留文本字段的值,我希望这会对您有所帮助。 – Adil 2012-08-12 11:54:27