我使用了两个提交按钮,一个用于在新标签页(预览)中打开页面,另一个用于普通表单提交(发布)。
我的问题是:
<form method="post" name="form">
Name : <br> <input type="text" name="name"/><br />
Address : <br> <input type="text" name="address"/><br />
<input name="publish" type="submit" value="Submit" onclick="action='proccess.php?action=submit';">
<input type="submit" value="preview" onclick='formpreview(this.form)'/>
</form>
<script>
function formpreview(form)
form.target = '_blank';
form.action = 'preview.php';
form.submit();
}
</script>
答案 0 :(得分:1)
删除
form.target = '_blank';
当您想要在新标签页中打开网页时,会出现 target="_blank"
。
修改强>
<form method="post" name="form" action="proccess.php?action=submit">
Name : <br> <input type="text" name="name"/><br />
Address : <br> <input type="text" name="address"/><br />
<button type="submit" value="Submit" name="publish" > Publish </button>
<button type="button" value="preview" onclick='formpreview(this.form)'>Preview</button
</form>
答案 1 :(得分:0)
您可以查看按钮值,然后随条件提交表单
<form method="post" name="form">
Name : <br> <input type="text" name="name"/><br />
Address : <br> <input type="text" name="address"/><br />
<input name="submit" type="submit" value="Submit" onclick="formpreview(this.form,this)">
<input type="submit" value="preview" onclick='formpreview(this.form,this)'/>
</form>
<script>
function formpreview(form,btn) {
alert(btn.value);
/*form.target='_blank';
form.action='preview.php';
form.submit();*/
if(btn.value=="preview"){
alert(btn.value);
form.target='_blank';
form.action='preview.php';
form.submit();
}
if(btn.value=="Submit"){
alert(btn.value);
form.target='_self';
form.action='proccess.php?action=submit';
form.submit();
}
}
</script>