javascrip捆绑事件和自定义事件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="jquery/jquery-1.10.1.js"></script>
<script type="text/javascript">
   $().ready(function(){
       for(var i=0;i<4;i++){
         //点击一次 多次执行
           /**
          $("input[name='mybutton']").click(function(){
            alert(111);
            });  */
             //解绑事件
             $("input[name='mybutton']").unbind("click");
             $("input[name='mybutton']").bind("click",function(){
                alert(111);
             });
            //自定义事件
             $("input[name='mybutton']").unbind("click");
             $("input[name='mybutton']").bind("click",function(){
                 $("input[name='mybutton']").trigger("getValue");  //在mybutton元素上自定义一个事件
             });
             $("input[name='mybutton']").unbind("getValue");    
             $("input[name='mybutton']").bind("getValue",function(){
               alert("my name is value");
               alert("I am tall");
               alert("I'm tall");
             });    
         }
   })
</script>
  </head>
  <body>
      <input type="button" name="mybutton" value="aaaa">
</html>

你可能感兴趣的:(JavaScript)