日期:2014-05-18  浏览次数:20553 次

在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!";
 }