亲宝软件园·资讯

展开

提交按钮的name='submit'引起的js失效问题及原因

人气:0

代码如下:

复制代码 代码如下:

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
</head>
<body>
<form id="pquery" method="post" action="supplierAction!list.action">
<div class="menu">
                商品名称:
                <input name="bill.goodsname" class="input-text" type="text">
                     是否付款:
                <select name="bill.pay">
                    <option value="">
                        请选择
                    </option>
                    <option value="01">
                        已付款
                    </option>
                    <option value="02">
                        未付款
                    </option>
                </select>
                    
                <!--就是因为下面这个按钮的名称叫做submit导致js失效-->
                <input name="submit" value="组合查询" class="button" type="submit">
            </div>
<div style="text-align: center;">每页显示
<select name="page.pageItems" onchange="gotoSelectedPage1()">
<option value="5">5</option>
<option value="10" selected="selected">10</option>
<option value="20">20</option>
<option value="50">50</option>
</select>条 共6条记录  第
<input id="curpage" name="page.currentPage" style="height:14px;line-height:14px; vertical-align:middle;color:#005aa7; border-bottom:1px solid #005aa7;border-top:0px;border-left:0px;border-right:0px;background-color:transparent;width:14px;text-align: center; " readonly="readonly" value="1" size="3">
页 / 共1页 <a href="javascript:page_first();">第一页</a>
<a href="javascript:page_last();">最后一页</a>  跳转页码至:
<select style="width: 40px;" id="selectpage" onchange="gotoSelectedPage()">
<option value="1" selected="selected">1</option></select></div>
<script type="text/javascript">
function sel(val){return document.getElementById(val);}
var page=sel('curpage');var form=sel('pquery');var select=sel('selectpage');
function page_first() {page.value = 1;form.submit();}
function page_pre() {var a = page.value;a = parseInt(a) - 1;page.value = a;page_validate();form.submit();}
function page_next() {var a = page.value;a = parseInt(a) + 1;page.value = a;page_validate();form.submit();}
function page_last() {page.value = 1;form.submit();}
function page_validate() {var a = page.value;if (a < 1){a = 1;}    if (a > 1){a = 1;}page.value = a;}
function gotoSelectedPage1() {page.value = 1;form.submit();}
function gotoSelectedPage() {page.value = select.value;form.submit();}
</script>
</div>
</form>
</body></html>

name属性删除之后正常运行~~这是什么原因呢,经过一番研究和咨询,一位大神给出了答案

form中元素通过name获取。如果name=submit,那么form.submit得到的应该是 那个input 。所以form.submit()会报 is not a finction 的错误

小伙伴们了解了没,希望本文能给大家一些帮助

加载全部内容

相关教程
猜你喜欢
用户评论