代码:在下面显示的代码中,警报消息一直循环直到语句结束。我需要一个警报语句只发出一次警报。如何实现这一点?
这里检查复选框的输出,如果未选中则显示未定义
for(j=1;j<=numOflimit;j++)
{
var select = $("input[name=select+j]:checked").val();
//alert (select);
//$check='undefined';
if(select==undefined)
{
alert ("Please select atleast one product");
}
else
{
var postData = $("form").serialize();//"product_name="+product_name+"&barcode="+barcode+"&Quantity"+Quantity;
$.ajax
({
type: 'POST',
url: 'http://localhost/example/index.php/castoutput',
data: postData,
success: function(html) {
// alert(html);
$('#cast2').html(html);
}
});
}
}
最佳答案
您可以创建一个变量,如果警报已被触发,一旦将其设置为 false 并检查 if,如果它是 true 或 false。
if (showAlert==true)
{
alert ("Please select atleast one product");
showAlert = false;
}
关于javascript - 如何在 JavaScript 循环中提醒一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7244777/