Html input 常見問題

來源:互聯網
上載者:User

標籤:推薦   file   content   arc   隱藏   斷行符號   pos   name   idt   

1.input斷行符號事件不執行導致頁面重新整理

情境:在文字框中輸入關鍵字按斷行符號,頁面自動重新整理了

<form name="keywordForm" method="post" action="">  <p id="profile_nav">  <label for="profile"> 關鍵字搜尋: </label>  <input style="width:80; height:20" type="text" name="keyword" onkeypress="searchKeywordKeyboard(event)" />  <input type="button" value="搜尋" onClick="searchKeyword()">  </p> </form>

解決方案1:

  一個表單下,如果只有一個文字框時,按下斷行符號將會觸發表單的提交事件。  既然是只有一個文字框才會出問題,那麼可以加一個隱藏的文字框

解決方案2:(推薦)

  <form name="keywordForm" method="post" action="" onsubmit="return false;">  就是在表單 form 後面加上一個 onsubmit 事件,返回 false,來阻止 form 提交。

 解決方案3:(不推薦)

document.onkeydown=function(e){        var e = e || event;        var currKey = e.keyCode || e.which || e.charCode;//支援IE,FireFox        if (currKey == 13) {            return false;        }    }

解決方案4:

<input type="text"  onkeydown="return ClearSubmit(event)" /> function ClearSubmit(e) {      if (e.keyCode == 13) {         return false;      }   }

 

 

 

Html input 常見問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.