Javascript 如果是这样,请停止执行
在这段代码中,我创建了行Javascript 如果是这样,请停止执行,javascript,Javascript,在这段代码中,我创建了行 $('.btn-process-request', node).bind('click', function(e){ e.preventDefault(); var data = {}; var fax_number_empty = {{ contract.request.customer.fax }} if (fax_number_empty == 0) { alert('Please, attach the fax number to you
$('.btn-process-request', node).bind('click', function(e){
e.preventDefault();
var data = {};
var fax_number_empty = {{ contract.request.customer.fax }}
if (fax_number_empty == 0) {
alert('Please, attach the fax number to your profile');
}
alert('Hello! What is your name?');
if ($(this).data('reason')) {
data.reason = prompt($(this).data('reason'));
if (!data.reason.length && $(this).data('reason-required')) {
alert($(this).data('reason-required'));
return false;
}
}
$.ajax({
url : $(this).attr('href'),
type: 'POST',
data : data,
success: function(data, textStatus, jqXHR) {
if (data.success) {
if (data.redirect_to) {
window.location.href = data.redirect_to;
}
else if (data.reload) {
window.location.reload();
}
}
else {
alert('Error! See console for details :(');
console.error(textStatus, data);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.error(textStatus, errorThrown);
}
});
return false;
});
我不知道如何正确地实现这一点。我想说,好的,如果contract.request.customer.fax为空,则显示一个警报,提示“请将传真号码附加到您的个人资料中。”这里最重要的是停止执行。换句话说,下面这些行的内容将不会被执行。谁有时间告诉我如何改进代码
另外,如果我的问题不清楚,请不要不好意思告诉我。如果字段传真号为空,请返回,函数将跳转到末尾,避免代码的其余部分
var fax_number_empty = {{ contract.request.customer.fax }}
if (fax_number_empty == 0) {
alert('Please, attach the fax number to your profile');
}
仅添加一个else{…}可能会重复错误,因此只有当fax_number_为空时才会执行else中的内容!=0.try`fax\u number\u empty==null`这会检查它是否为null,如果typeoffax\u number\u empty==undefined,这是什么意思?把底线放在{}和else之间?
if (!fax_number_empty) {
alert('Please, attach the fax number to your profile');
return;
}