![](/img/trans.png)
[英]How to break out from jQuery click event function from inside $.each
[英]Jquery: How to break out of each() and the function it's inside in?
$("#savebtn").click(function() {
$('.mytable tr').each(function(){
if($('.mytable tr').length < 1){
alert("Nothing in the table!")
return
}
});
alert("You are still inside the click function")
});
對此有一點麻煩。 我想退出jquery每個循環並完全單擊功能。 但是“返回”只是讓我退出了每個循環。 如何完全退出點擊功能?
如果表中沒有任何內容,則each
函數實際上將永遠不會執行 (因為要迭代的集合為空)。
也許您打算將條件作為click
功能的第一行:
$("#savebtn").click(function() {
if($('.mytable tr').length < 1) {
alert("Nothing in the table!");
return;
}
$('.mytable tr').each(function() {
doSomething(this);
});
alert("You are still inside the click function")
});
附帶說明一下,如果each
功能都是該塊中的唯一內容,則無需為空表情況做任何特殊的事情,因為每個功能將簡單地執行零次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.