2014-01-11 88 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

相關問題