通过submit 来提交表单是什么意思

2025-06-29 04:01:13
推荐回答(1个)
回答1:

原来的代码:————————————————————————————————————————
HTML里
//type="button" name="button"
value="搜索"onclick="searchshow()"/>
JS里
function searchshow(){
var cont = document.getElementByIdx_x_x_x_x_x_x_x("searchtext").value;
window.open('searchshow.php?cont='+cont+'&action=null&display=show','newwindow');
//只是传参给后台,不算是真正的打开
}
PHP里
$cont = $_GET['cont'];
$action=$_GET['action'];
$display=$_GET['display'];
//接受JS里传来的参数
$tpl->assign('searchList',$searchArray);
$tpl->assign('num',$num);
$tpl->assign('cont',$cont);
$tpl->display('searchshow.tpl');
//在此处可以要求打开新的页面。
(此时感悟到ajax一般是用在同一个页面的刷新显示中)
修正的新用法submit如下—————————————————————————————————
HTML里

//


//注意一定要写return 这样js 判断才会有效哦
//名字(最多 10 个字符):

//
JS里 //判断值不为空
function jstry(){
var start= document.getElementByIdx_x('start').value;
var end = document.getElementByIdx_x('end').value;
if (start=="")
{
alert("please input the startpoint");
return false;}
if (end=="")
{
alert("please input the endpoint");
return false;}
if (start > end)
{
alert("make sure,start < end ");
return false;}
}
PHP里
应该和上面一样,就是display一下吧。
1、补充说一点,如果在form表单里写method=post,那么在PHP中就直接用$a=$_post['name'],就可以获得到他的值,非常非常方便,我才发现我之前编程真是一坨x,我还在JS里面用一种很老掉牙的方式穿过去。他妹子的。怎么没有早点发现呢。
2、一般就用submit来提交就好了,若需要有验证,在form属性里用onsubmit=aaa();若验证通过了,才会向x.php发过去哦。
更多内容可参考http://www.viiboo.cn