zoukankan      html  css  js  c++  java
  • 在服务器控件中加入客户端脚本

     

    1

    <asp:Button id="button1" onmouseout="this.style.backgroundColor='blue'" onmouseover="this.style.backgroundColor='green'" runat="server" Text="Button"></asp:Button>

    2

    private void Page_Load(object sender, System.EventArgs e)

            {

                // 在此处放置用户代码以初始化页面

                this.Button1.Attributes["onclick"]="javascript:return confirm('你确定吗?')";

            }

    3 调用自定义的javascript

    private void Page_Load(object sender, System.EventArgs e)

               {

                // 在此处放置用户代码以初始化页面

                this.Button1.Attributes["onclick"]="javascript:return test();";

            }

    在页面文件中的脚本代码:

    <script language="javascript">

    <!--

    function test()

    {

      if(表单ID号.TextBox1.Value=="")

    {

       alert("没有输入值");

       return false;

    }

    }

    //-- >

    </script>

    4.在脚本中绑定事件

    页面文件中的脚本代码:

    <SCRIPT for="Button1" event="onclick()" LANGUAGE="javascript">

    <!--

      return confirm("你确定要点击吗?");

    //-- >

    </SCRIPT>

  • 相关阅读:
    HTML学习笔记2
    HTML的学习笔记
    Unsupported major.minor version 51.0解决办法
    java出现The type java.lang.Object cannot be resolved. It is indirectly referenced.....解决办法
    切片
    switch语句
    if-else语句与for循环
    闭包函数
    函数
    常量
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172594.html
Copyright © 2011-2022 走看看