999热在线精品观看全部,欧美精品一区二区久久,亚洲一区二区约美女探花,国产精彩视频在线观看免费蜜芽,免费国产a,国产精品一久久香蕉国产线看,国产六区

待解決問題
  1. 網(wǎng)頁Form只有一個(gè)input框時(shí),按回車后表單就直接提交了,輸入檢測函數(shù)不起作用?

    完善時(shí)間:2013-03-13 15:34:22會員:貝加達(dá)目錄:電腦網(wǎng)絡(luò) - 網(wǎng)站建設(shè)瀏覽:6527 次

    下例中的 TestForm 表單中只有一個(gè)名稱為 TestInput 輸入框,當(dāng) TestInput 輸入框處于聚焦?fàn)顟B(tài)時(shí),按回車表單直接就提交了,而沒有通過輸入檢測函數(shù) CheckInput() 進(jìn)行合法性檢查,當(dāng)表單中有多個(gè)輸入框時(shí)沒有此問題,請問這種問題有沒有什么辦法解決?

    <form name="TestForm" method="post" action="test.asp?act=test">
       請輸入6位數(shù)字:<input name="TestInput" type="text" tabindex="1" maxlength="6">
       <a href="javascript:void(0);" onclick="javascript:CheckInput();return false;">測試</a>
    </form>
    
    <script type="text/javascript">
       //輸入檢測函數(shù)
       function CheckInput(){
          if(!(/^(\d{6})$/).test(document.TestForm.TestInput.value)){
             alert("請檢查輸入是否有誤!");
             document.TestForm.TestInput.focus();
             return false;
          }
          document.TestForm.submit();
          return true;
       }
    </script>

     

熱心回答(共1條)
  1. 第1條回答

    完善時(shí)間:2013-03-13 15:51:46會員:倩華

    你可以嘗試以下方法來解決:

    1、在 Form 中加入提交檢測

    <form name="TestForm" method="post" action="test.asp?act=test" onsubmit="javascript:CheckInput();return false;">
       請輸入6位數(shù)字:<input name="TestInput" type="text" tabindex="1" maxlength="6">
       <a href="javascript:void(0);" onclick="javascript:CheckInput();return false;">測試</a>
    </form>

     

    2、加一個(gè)不顯示的輸入框

    <form name="TestForm" method="post" action="test.asp?act=test">
       請輸入6位數(shù)字:<input name="TestInput" type="text" tabindex="1" maxlength="6">
       <input type="text" name="FixEnter" style="display:none;">
       <a href="javascript:void(0);" onclick="javascript:CheckInput();return false;">測試</a>
    </form>

     

    3、在輸入框加入回車檢測:

    <form name="TestForm" method="post" action="test.asp?act=test">
       請輸入6位數(shù)字:<input name="TestInput" type="text" tabindex="1" maxlength="6" onkeydown="javascript:if(event.keyCode==13){CheckInput();return false;}">
       <a href="javascript:void(0);" onclick="javascript:CheckInput();return false;">測試</a>
    </form>

     

    個(gè)人覺得優(yōu)先使用第1種、第2種方法,第3種方法跟蹤并判斷onkeydown擊鍵事件,效率較低,不推薦使用。

聯(lián)系方式:

南京貝加達(dá)電子科技有限公司

  • 地址:南京市江北新區(qū)柳州北路21號滌太太科技大樓2F
  • 聯(lián)系人:焦倩華(先生)
  • 手機(jī):13813916308
  • 郵箱:Ser@bekda.com
  • 服務(wù)專線:400-8282-116
©2010-2025 Bekda Electronic Technology Co., Ltd. All right reserved.

蘇公網(wǎng)安備 32011102010041號

320111201705278429

蘇ICP備12027725號

延津县| 宜良县| 墨江| 广安市| 江门市| 宣恩县| 耒阳市| 滕州市| 白城市| 民权县| 抚顺县| 平泉县| 都昌县| 沿河| 永顺县| 乐东| 安宁市| 安龙县| 黔西| 兴安县| 南投市| 永吉县| 温宿县| 通化市| 绥江县| 西宁市| 斗六市| 台北县| 札达县| 定兴县| 吉水县| 望都县| 五华县| 汾西县| 哈尔滨市| 聊城市| 温州市| 鄂托克旗| 河曲县| 龙州县| 安多县|