页面标签事件怎么调用jQuery变量?例如我定义了变量:var dd=function(){
jQuery("body").addClass("hh");
};然后我想在Button里的onclik调用那个 变量dd,请问怎么写onclick?

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript" src="jquery-1.2.6.js"></script>
    <script type="text/javascript">
    $(function(){
    var dd=function(){
    jQuery("body").addClass("hh");
    };

    $("#btn").click(dd); })
    </script>
    <style type="text/css">
    .hh{
    background-color:blue;
    }
    </style>
    </head><body>
    <input id="btn" type="button" value="CLICK ME"/>
    </body>
    </html>
      

  2.   

      $("#btn").click(dd);
      

  3.   

    一种 是直接在<input>标签里写上onclick="dd();"
    另一种 是在<script>标签里写上$(function(){
       $("#btn").click(dd)
       //或者 $("#btn").bind("click",dd);
    })