DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 提交按鈕的name=submit引起的js失效問題及原因
提交按鈕的name=submit引起的js失效問題及原因
編輯:關於JavaScript     

代碼如下:

復制代碼 代碼如下:
<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 的錯誤

小伙伴們了解了沒,希望本文能給大家一些幫助

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved