如何逃避...每个循环和方法在同一时间? [英] How to escape from for ... each loop and method at the same time?
本文介绍了如何逃避...每个循环和方法在同一时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用下面的代码,迭代选择选项。我检查了是否已输入选项值。它从...中转义,但不会退出方法。
I am using the code below, that iterating over select options. I checked if options value has already entered. It escapes from for-each but it doesn't exit from method.
yeniIlacBagla_ilacBagla: function(){
$("#bagliIlaclar > option").each(function(){
if(this.value===$("#baglanacakIlacID").val()){
alert($("#baglanacakIlacAdi").val()+'\n adlı ilaç zaten bağlıdır!');
return;
}else{
$("#bagliIlaclar").append($('<option></option>').val($("#baglanacakIlacID").val()).html($("#baglanacakIlacAdi").val()));
}
});
}
推荐答案
根据 jquery的文档我发现以下
通过使
回调函数返回false ,我们可以在特定的迭代中打破$ .each()循环。返回非false与for循环中的
continue语句相同;它将立即跳到下一个
迭代。
We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
这篇关于如何逃避...每个循环和方法在同一时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文