zoukankan      html  css  js  c++  java
  • 两点东西

    一,form的onsubmit button的onclick事件
    <html>
    <head>
        <title>a test for submit</title>
        <script language="javascript">
         function test1()
         {
           alert("this form will not be submitted!");
           return true;//如果是false则form 的onsubmit事件将不被执行了
         }
         function test()
         {
            alert("submitform");//如果是false执行也将中止
         }
         //提交执行顺序是先submit的onclick,然后是form的onsubmit事件
        </script>
    </head>
    <body>
    <form id="form1" onsubmit="return test()" action="Default.aspx">

    <input type="submit" onclick="return test1()" />
    </form>

    </body>
    </html>
    二给button加onclick事件
    <html>
    <head runat="server">
        <title>test button</title>
        <script language="javascript" type="text/javascript">
        function checkUser()
        {
           var user=$("txtName").value;
           if(user.length==0&&user=="")
           {
              alert("you didn't input anything!");
              user.value="";
              return false;
           }
           return true;
        }
       
        function $(id)
        {
           return document.getElementById(id);
        }
       
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtName" runat="server" EnableViewState="False"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" EnableViewState="False" /></div>
        </form>
    </body>
    </html>
    后台代码

        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Button1.Attributes.Add("onclick", "return checkUser()");
            }

            protected void Button1_Click(object sender, EventArgs e)
            {
                Response.Write("this is a good day!");
            }
        }


     

  • 相关阅读:
    codeforces 719A:Vitya in the Countryside
    POJ3233 Matrix Power Series
    codevs1409 拦截导弹2
    BZOJ1562 [NOI2009]变换序列
    POJ1325 Machine Schedule
    codeforces 715B:Complete The Graph
    BZOJ1972:[SDOI2010]猪国杀
    浅谈模拟
    BZOJ2548:[CTSC2002]灭鼠行动
    BZOJ1033:[ZJOI2008]杀蚂蚁
  • 原文地址:https://www.cnblogs.com/applesuch5/p/1320150.html
Copyright © 2011-2022 走看看