<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
       
    
     <script language="javascript">
     function a()
     {
       alert("aaa");
      document.form1.b.value="bbb";
       
     }
     </script>
   
    
    
</head>
<body>
   
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
        <input id="Button2" name="b"  type="button" value="button" onclick ="a()"/>
      
        <input id="Text1" name="b"  type="text" value="aaa" />
        
    </form>
</body>
</html>
--------------------------------------
当我点击button2的时候为什么text1的值没有变化.

解决方案 »

  1.   

    document.form1.b.value="bbb";
    改为
    document.all["Text1"].value="bbb";
      

  2.   

    就是哈1!JAVASCript中,如果没有制定 ID,用name,否则用ID
      

  3.   

    document.getElementById("Text1").value="bbb";orwith(form1)
    {
       Text1.value = "bbb";
    }
      

  4.   

    可以了.谢谢.嘿嘿嘿
    asp.net里的js和一般的js有不同吗?
      

  5.   

    <input id="Button2" name="b"  type="button" value="button" onclick ="a()"/>
          
    <input id="Text1" name="b"  type="text" value="aaa" />
            
    javascript 都一样的,没什么不同。只是你注意了没,你两个html控件的名字都叫"b"通过name或者id都可以获得该控件的