2014-01-11 64 views
0

我需要注册一个点击事件,并需要调用相同的事件,当我点击(“$ P2”)元素注册一个点击事件并调用同一事件

<html> 
    <head> 
     <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 

     <script> 
      $(document).ready(function(){ 
       $("#p1").on('click', function(event) { 
        console.log('clicked = ', $(this).text()); 

        $("#p2").on('click', function(event) {  
        $("p").trigger('click'); 
         }) 
       }) 

      }); 
     </script> 

     <style> 
     </style> 
    </head> 
    <body> 
     This is a scratch html. 
     <br> 
     <p id="p1">This is paragraph - p1</p> 
     <p id="p2">This is paragraph - p2</p> 
    </body> 
    </table> 
</html> 
+1

像http://jsfiddle.net/arunpjohny/Wchfk/1/ –

回答

0

我想你在找什么是多个选择器

$(document).ready(function() { 
    $("#p1, #p2").on('click', function (event) { 
     console.log('clicked = ', $(this).text()); 
    }) 
}); 

演示:Fiddle

相关问题