首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

在JavaScript中,怎么对TextBox的值进行修改

2012-04-27 
在JavaScript中,如何对TextBox的值进行修改?if (confirm(你确认要删除记录吗?)) {//var txtBox1 docum

在JavaScript中,如何对TextBox的值进行修改?
if (confirm("你确认要删除记录吗?")) {
  //var txtBox1 = document.getElementById("TextBox_Del");
  //txtBox1.value = "yes";

  //document.form1.TextBox_Del.value = "yes";
  document.all["TextBox_Del"].value = "yes";
  }
  else {
  //var txtBox1 = document.getElementById("TextBox_Del");
  //txtBox1.value = "no";
  //document.form1.TextBox_Del.value = "no";
  document.all["TextBox_Del"].value = "no";
  }
TextBox_Del的AutoPostBack="True",上面的三种方法,我都试了,都不成功。我在aspx.cs文件中,用:
string MessageBox = TextBox_Del.Text;取出来的值总是空字符串。这是为什么?

[解决办法]
var obj = document.getElementById("<%=TextBox_Del.ClientID %>");
if(confirm("delete?")){
obj.value = "yes";
}else{
obj.value = "no";
}

[解决办法]

HTML code
<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title>    <script type="text/javascript">        function textchange(){            var obj = document.getElementById("<%=TextBox_Del.ClientID %>");             if(confirm("delete?")){                 obj.value = "yes";             }else{                 obj.value = "no";             }         }    </script></head><body>    <form id="form1" runat="server">    <div>    <asp:Literal ID="li_showValue" runat="server" /><br />    <asp:TextBox ID="TextBox_Del" onchange="textchange();" runat="server" AutoPostBack="true" />    </div>    </form></body></html>
[解决办法]
我是这么写的 可以的
前台:
JScript code
 function clicked() {    document.getElementById('TextBox3').value="Hello Word!"; } 

热点排行