![](/img/trans.png)
[英]JQuery, how can I call another JQuery function that's (id).on(click, function)
[英]How can I call click function to another click function in jQuery
我有2個按鈕。 當我單擊按鈕1時,按鈕2被禁用,而按鈕1被關閉時,按鈕2被啟用。 我正在使用觸發器(“點擊”),然后發生錯誤“超出最大調用堆棧大小”。 我怎么解決這個問題。
$("#btn1").click(function(){
$('#box1').css('display','block');
$('#box1').addClass('tint');
$("#btn2").off('click');
});
$("#btn2").click(function(){
alert("Button 2 was clicked");
});
$('#boxclose1').click(function(){
$('#box1').hide();
$("#btn2").on("click", function(){
$('#btn2').trigger("click"); error here
});
});
$("#btn2").on("click", function(){
$('#btn2').trigger("click"); error here
});
這是函數綁定到元素#btn2上的click事件的遞歸調用
這很好
您可以使用
.prop("disabled",true);
禁用和
.prop("disabled",false);
啟用按鈕
$("#btn1").click(function(){ $('#box1').css('display','block'); $('#box1').addClass('tint'); $("#btn2").prop('disabled', true); }); $("#btn2").click(function(){ alert("Button 2 was clicked"); }); $('#boxclose1').click(function(){ $('#box1').hide(); $('#btn2').prop('disabled', false); });
#box1 { display:none; } .tint { color: #ff0000; }
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> <div id="box1">Box 1</div> <button id="btn1">Button 1</button> <button id="btn2">Button 2</button> <button id="boxclose1">Box Close</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.