![](/img/trans.png)
[英]How to stop event from firing multiple times in onClick function with React?
[英]How do I stop .focusout() from firing multiple times?
這是我嘗試做的簡單再現:
https://jsfiddle.net/L9k4g2vw/1/
$('body').on('focusout', 'input', function(){
alert('test');
});
<input type="text" name="textbox1" />
<input type="text" name="textbox2" />
當你從<input>
聚焦時,它運行正常,但是,如果你將<input>
直接聚焦到另一個<input>
,它會創建一個循環。 我究竟做錯了什么? 謝謝!
希望這有幫助......我使用了JQuery ....
$("<input />", { type: "number", min: "0" }).addClass("someclass").appendTo($("#someid")); $(document).on("focusout", ".someclass", function() { console.log("alert"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="someclass" /> <div id='someid'> </div>
alert
焦點。 如果您不使用alert
(或其他舊的已棄用函數confirm
, prompt
等;例如,1990年代的風格帶來世界到停止功能),您的代碼就可以了:
$('body').on('focusout', 'input', function(){ console.log('test'); });
<input type="text" name="textbox1" /> <input type="text" name="textbox2" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.