簡體   English   中英

如何從其他jquery函數調用jquery click函數

[英]how to call jquery click function from other jquery function

如何從其他jquery函數調用jquery click函數。

我嘗試使用觸發功能無法正常工作。

這是我的jQuery函數

$('#index1').click(function(event){
    $('#index2').trigger('click');
});

$('#index2').click(function(event){
   alert("Hello");
});

我想從#index1函數調用#index2函數。

這是工作示例:

確保已添加一個jQuery庫

 $('#index1').click(function(event){ $('#index2').trigger('click'); }); $('#index2').click(function(event){ alert("Hello"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <h2 id="index1"> Index 1 </h2> <h4 id="index2"> Index 2 </h4> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM