<form method="get" action="/" onsubmit="SubmitForm()">
<input type="text" title="" value="" name="q" class="search-input" id="gsearch" />
<input type="submit" value="" name="sa" id="search-button"/>
</form>
<script type="text/javascript">
function SubmitForm(){
window.open("http://test.com/gsearch.php?cx=015214977:8tebxhu0mrk&cof=FORID:11&ie=GB2312&as_q="+document.getElementById('gsearch').value);
return false;
}
</script>
当我提交按钮时,原始页面刷新一次。如何预防它?谢谢。为什么页面刷新一次?
没关系。谢谢。为什么添加回报。有用?谢谢。 – zhuanzhou
onsubmit属性是一个JavaScript脚本。如果该脚本返回false,则不会提交表单。首先,你的脚本是_SubmitForm()_,它只是调用函数,并且没有_return false_。但在插入返回后,现在在onsubmit脚本中,返回SubmitForm的返回值,该值为false。 – Saeed