Re: [請益] 請問text輸入

看板Web_Design作者 (me so f**ked up!)時間19年前 (2006/09/19 03:23), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《jokker (微雨從東來)》之銘言: : function CheckID(){ : if((event.keyCode>=32)&&(event.keyCode<=126)) : return true; : else : return false; : } : <input name="ID" type="text" id="ID" onKeyPress = "return CheckID()"> : 以上是我原來網頁的長相 : 現在, 我不想要讓使用者輸入的第一個字元是空白字元, 如 [空白]abc : 但是我希望在接下來的字串是可以有空白的 , 如 ab[空白]c : 請問我要怎麼做 ?? 試試看這樣: function CheckID(event, txtFld) { var keyCode, charCode; if (event.charCode == undefined) { keyCode = 0; charCode = event.keyCode; } else { keyCode = event.keyCode; charCode = event.charCode; } return keyCode || (charCode > 32 && charCode <= 126) || (charCode == 32 && txtFld.value.length > 0); } <input name="ID" type="text" id="ID" onkeypress="return CheckID(event, this)"> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.131.0.110 ※ 編輯: elan 來自: 220.131.0.110 (09/19 03:37)

09/19 11:36, , 1F
太感謝了~ 完全解決我的問題, 謝謝!!
09/19 11:36, 1F
文章代碼(AID): #153l99_W (Web_Design)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #153l99_W (Web_Design)