本人新手,请大虾们不要介意,有一个按钮,当点击他的时候会触发里面的事件,   $(".A").click(function () {
            //方法
        })现在我想点击另一个按钮,然后触发.A里面的事件应该怎么弄呢? 我看网上写的
if($("#B").click(function(){
 $(".A").trigger("click");
}但是这样没有效果啊? 各位大侠麻烦告诉下应该怎么写才能点击#B的时候触发.A里的事件呢?

解决方案 »

  1.   

    if($("#B").click(function(){
     这一句,是不是少个)啊
      

  2.   


    没少,刚才在CSDN上忘写)了.呵呵
      

  3.   

    <!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=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function() {
    function bg() {
    $("#A").css("background-color", "red");
    alert("A的背景色设置为红色了");
    }
    $("#A").click(bg);
    $("#B").click(bg);
    });
    </script>
    </head><body>
    <div id="A" style="width:200px; height:200px; background-color:blue;"></div>
    <input type="button" id="B" value="button" />
    </body>
    </html>
      

  4.   

    <html><head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("#button1").click(function(){
         alert($(this).val());
      });  $("#button2").click(function(){
         $("#button1").trigger('click');
      });
    });
    </script>
    </head><body>
    <p>If you click on me, I will disappear.</p>
    <input type=button value='button one' id='button1' > 
    <input type=button value='button two' id='button2' > 
    </body></html> 没有问题,$(".A").click这个在那里写的,是不是没有生效