javascritp實現(xiàn)input輸入框相關(guān)限制用法
更新時間:2007年06月29日 00:00:00 作者:
1.取消按鈕按下時的虛線框
在input里添加屬性值 hideFocus 或者 HideFocus=true
2.只讀文本框內(nèi)容
在input里添加屬性值 readonly
3.防止退后清空的TEXT文檔(可把style內(nèi)容做做為類引用)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>
4.ENTER鍵可以讓光標(biāo)移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >
5.只能為中文(有閃動)
<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">
6.只能為數(shù)字(有閃動)
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
7.只能為數(shù)字(無閃動)
<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
8.只能輸入英文和數(shù)字(有閃動)
<input onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
9.屏蔽輸入法
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">
10. 只能輸入 數(shù)字,小數(shù)點,減號(-) 字符(無閃動)
<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
11. 只能輸入兩位小數(shù),三位小數(shù)(有閃動)
<input maxlength=9 onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,'.')" onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>
------------------------------------------------------------------------
<input type="text" name="input1" value="中國">
怎樣使input中的內(nèi)容為只讀,也就是說不讓用戶更改里面的內(nèi)容。
<input type="text" name="input1" value="中國" onfocus=this.blur()>
<input type="text" name="input1" value="中國" readonly>
<input type="text" name="input1" value="中國" disabled>
最好不要用disabled,不然就無法取出里面的值了.
<input type="text" name="input1" value="中國" readonly="true">
<input type="text" name="input1" value="中國" readonly style="color:#999 ;">
在input里添加屬性值 hideFocus 或者 HideFocus=true
2.只讀文本框內(nèi)容
在input里添加屬性值 readonly
3.防止退后清空的TEXT文檔(可把style內(nèi)容做做為類引用)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>
4.ENTER鍵可以讓光標(biāo)移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >
5.只能為中文(有閃動)
<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">
6.只能為數(shù)字(有閃動)
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
7.只能為數(shù)字(無閃動)
<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
8.只能輸入英文和數(shù)字(有閃動)
<input onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
9.屏蔽輸入法
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">
10. 只能輸入 數(shù)字,小數(shù)點,減號(-) 字符(無閃動)
<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
11. 只能輸入兩位小數(shù),三位小數(shù)(有閃動)
<input maxlength=9 onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,'.')" onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>
------------------------------------------------------------------------
<input type="text" name="input1" value="中國">
怎樣使input中的內(nèi)容為只讀,也就是說不讓用戶更改里面的內(nèi)容。
<input type="text" name="input1" value="中國" onfocus=this.blur()>
<input type="text" name="input1" value="中國" readonly>
<input type="text" name="input1" value="中國" disabled>
最好不要用disabled,不然就無法取出里面的值了.
<input type="text" name="input1" value="中國" readonly="true">
<input type="text" name="input1" value="中國" readonly style="color:#999 ;">
您可能感興趣的文章:
- Android文本輸入框(EditText)輸入密碼時顯示與隱藏
- Android實現(xiàn)動態(tài)顯示或隱藏密碼輸入框的內(nèi)容
- Android軟鍵盤擋住輸入框的終極解決方案
- 5種方法完美解決android軟鍵盤擋住輸入框方法詳解
- Android高級xml布局之輸入框EditText設(shè)計
- 解決Android軟鍵盤彈出覆蓋h5頁面輸入框問題
- Android UI設(shè)計系列之自定義EditText實現(xiàn)帶清除功能的輸入框(3)
- Android仿支付寶自定義密碼輸入框及安全鍵盤(密碼鍵盤)
- Android 仿支付寶密碼輸入框效果
- android仿微信支付寶的支付密碼輸入框示例
- java swing實現(xiàn)QQ賬號密碼輸入框
相關(guān)文章
利用JavaScript更改input中radio和checkbox樣式
利用JavaScript更改input中radio和checkbox樣式的實現(xiàn)代碼。2009-11-11javascript select列表內(nèi)容按字母倒序排序與按列表倒序排列
javascript select列表內(nèi)容按字母倒序排序與按列表倒序排列...2007-08-08select 控制網(wǎng)頁內(nèi)容隱藏于顯示的實現(xiàn)代碼
js下通過select的控制實現(xiàn)內(nèi)容的隱藏于顯示,需要的朋友可以參考下。2010-05-05Javascript 表單之間的數(shù)據(jù)傳遞代碼
今天有朋友問我關(guān)于用JAVASCRIPT來進行頁面各表單之間的數(shù)據(jù)傳遞的問題,我以前也寫過,不過從來沒有注意,今天總結(jié)了一下,希望能夠給大家一些幫助,也幫助我總結(jié)以前學(xué)過,用過的知識。2008-12-12JS option location 頁面跳轉(zhuǎn)實現(xiàn)代碼
JS中l(wèi)ocation對象 在option中的應(yīng)用(跳轉(zhuǎn)采單),方便通過 option實現(xiàn)頁面的切換2008-12-12