ajax - JavaScript Ajax - Prevent Division by Zero Function
问题描述
I am building a calculator for a class using AJAX. I am having issues with my if else statement not working. It is supposed to display an alert, telling the user that they cannot divide by zero except the alert never shows. I am a beginner to Ajax, if anyone could provide guidance, it'd be greatly appreciated - I know it's probably something simple that I'm overlooking. Below is my function:
...
}
function divFunc() {
var fn = "divide";
getResult(fn);
event.preventDefault();
return;
if (frmMain.txtBxSecNum.value == 0) {
$('#alert').text("You cannot divide by zero!");
}
else { (frmMain.txtBxFirstNum.value == 0)
$('#alert').text("You cannot divide by zero!");
}
}
...
解决方案
请去掉『return;』</p>
该语句不起作用,因为上面添加了return,所以不执行下面的语句