我试图检查变量的值是否为空,但它不起作用。我还必须停止脚本并且不要插入行
网页
<input type="text" name="for_intitule" id="form_intitule">
Run Code Online (Sandbox Code Playgroud)
jQuery
var form_intitule = $('input[name=form_intitule]').val();
if(form_intitule == null){
alert('fill the blank');
return false;
}
Run Code Online (Sandbox Code Playgroud)
更新 :
$('#insertForm').on('click', function(){
var form_intitule = $('input[name=form_intitule]').val();
if($('input[name=form_intitule]').val().trim().length == 0){
alert('fill the blank');
}
$.ajax({
type: "GET",
url: "lib/function.php?insertForm="+insertForm+"&form_intitule="+form_intitule,
dataType : "html",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
success:function(data){
}
});
});
Run Code Online (Sandbox Code Playgroud) 我有以下代码,如果第一个IF为真,我需要停止功能,我不会执行其余的代码.
你可以帮帮我吗 ?谢谢 !:)
function valideInfosReclamation($date,$idSite,$idNature,$idActivite){
if($date==""){
ajouterErreur("Le champ date ne doit pas être vide");
}
else{
if(!estDatevalide($date)){
ajouterErreur("Date invalide");
}
}
if($idSite || $idNature || $idActivite == ""){
ajouterErreur("Certains champs sont vides et doivent êtres remplis");
}
}
Run Code Online (Sandbox Code Playgroud)