js提交表單 TypeError: document.reqForm1.submit is not a function 問題

方式1:      

form action="/order/?act=order" method="post" name="rep1">

          <div class="discount_info_l_inp"><input type="text" οnblur="if(this.value == '' ) this.value='請輸入優惠碼';" οnfοcus="if(this.value == '請輸入優惠碼' ) this.value='';"  value="<{if $coupon_check}>該優惠碼不可用  請輸入新優惠碼<{elseif $coupon_over}>每份菜只能使用一次優惠券<{else}>請輸入優惠碼<{/if}>" name="coupon_code"></div>

                <div class="discount_info_r" ><a href="javascript:document.rep1.submit();" >確定</a></div>

             </form>

方式2:

form action="/order/?act=order" method="post" name="rep1">

         <div class="discount_info_l_inp"><input type="text" οnblur="if(this.value == '' ) this.value='請輸入優惠碼';" οnfοcus="if(this.value == '請輸入優惠碼' ) this.value='';"  value="<{if $coupon_check}>該優惠碼不可用  請輸入新優惠碼<{elseif $coupon_over}>每份菜只能使用一次優惠券<{else}>請輸入優惠碼<{/if}>" name="coupon_code"></div>
                <div class="discount_info_r" ><a href="javascript:document.forms['rep1'].submit();" >確定</a></div>    
                </form>


最開始按照方式1通過js提交表單,表單正常提交,未報任何錯誤,如此提交數次後,火狐瀏覽器報錯 TypeError: document.reqForm1.submit is not a function .從網上搜索的答案來看,有些此類報錯是由於<input type="submit" name="submit" /> ,或者是html 元素name出現html關鍵字 ,所以報錯。但是上面代碼並沒有關鍵字問題,後來偶然發現js提交表單的正確格式是javascript:document.forms['rep1'].submit();  改成此種格式,報錯消失。  

發佈了3 篇原創文章 · 獲贊 2 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章