我有这个html文本输入和javascript代码:
<input type="text" name="statuspopup" id="statuspopup" value="" />
<script type="text/javascript">
function SubmitTicketForm() {
return CheckRequired();
if($('#statuspopup').val() == '') {
//do status popup here
alert("status");
} else {
//just submit the form
$('form1').submit();
}
}
</script>
然后我有这个提交按钮:
<input type="submit" onclick="SubmitTicketForm();" name="submit" id="submit" value="Save" />
所以它应该显示一个javascript警报,但它没有这样做。
答案 0 :(得分:2)
立即返回CheckRequired()
函数调用后,函数停止执行。假设它返回BOOL值,你的函数应如下所示:
function SubmitTicketForm() {
if( CheckRequired() === false ) {
return false;
}
if($('#statuspopup').val() == '') {
//do status popup here
alert("status");
} else {
//just submit the form
$('form1').submit();
}
}
您的表单选择器似乎也是错误的。没有form1
这样的html元素,如果它是ID,则#form1
或.form1
如果它的类名
答案 1 :(得分:0)
函数在return语句后结束。返回函数后写入的所有内容都将被忽略。最后放回。
<input type="text" name="statuspopup" id="statuspopup" value="" />
<script type="text/javascript">
function SubmitTicketForm() {
if($('#statuspopup').val() == '') {
//do status popup here
alert("status");
} else {
//just submit the form
$('form1').submit();
}
return CheckRequired();
}
</script>
答案 2 :(得分:0)
将返回放在函数的末尾,如下所示:
function SubmitTicketForm() {
if($('#statuspopup').val() == '') {
//do status popup here
alert("status");
} else {
//just submit the form
$('form1').submit();
}
return CheckRequired();
}
答案 3 :(得分:0)
<input type="submit" onclick="SubmitTicketForm();" name="submit" id="submit" value="Save" />
<script type="text/javascript">
function SubmitTicketForm() {
if($('#statuspopup').val() == '') {
//do status popup here
alert("status");
} else {
//just submit the form
$('form1').submit();
}
return CheckRequired();
}
</script>
现在替换它谢谢
答案 4 :(得分:0)
function SubmitTicketForm()
{
if(!CheckRequired() && $('#statuspopup').val() == '') {
//do status popup here
alert("status");
return false;
} else {
//just submit the form
//$('form1').submit();
return true; //it's a submit button...will submit by itself. if you want to
//manually submit with jquery, make it a button
}
}
并且不要忘记为你的onclick添加一个回复:
<input type="submit" onclick="return SubmitTicketForm();" name="submit" id="submit" value="Save" />
再一次,知道检查是什么以及它为什么会有用!