这是HTML
<input class="btn" onClick="return IsEmpty()" type="submit" name='submit' value="submit"/>
javascript
function IsEmpty(){
if(document.forms['form'].name.value == "")
{
alert("empty");
return false;
}
if(document.forms['form'].name.value != ""){
alert('Thank You, Your order is being processed');
return true;
}
}
我想要做的是只有填写完所有字段才能显示感谢警报。目前,该表单捕获了缺少的输入,但仍然会发出感谢信息。
答案 0 :(得分:4)
请尝试:
function IsEmpty() {
if (document.forms['form'].name.value == "") {
alert("empty");
return false;
}
alert('Thank You, Your order is being processed');
return true;
}
答案 1 :(得分:3)
试试这个
function IsEmpty(){
if(document.forms['form'].name.value == "")
{
alert("empty");
return false;
}
if(document.forms['form'].name.value != ""){
alert('Thank You, Your order is being processed');
return true;
}
}
&#13;
<form name="form" action="">
<input name="name" />
<input class="btn" onClick="return IsEmpty()" type="submit" name='submit' value="submit" />
</form>
&#13;