熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Javascript >> 正文

jquery實現文本框只能輸入數字

2022-06-13   來源: Javascript 

  如下是例子的部分代碼(個方法都可以)
<script type="text/javascript">
$(document)ready(function() {
onlyNum("test");
}

//文本框只能輸入數字不能輸入小數點和字母 by john
function onlyNum(id){
$("#"+id)keydown(function(event)
{ var keyCode = eventwhich;
if (keyCode == || keyCode == || keyCode == || keyCode == || (keyCode >= && keyCode <= ) || (keyCode >= && keyCode <= ) )
{ return true; }
else { return false } }
)focus(function()
{ thisstyleimeMode = disabled; }
);
}
//文本框只能輸入數字和小數點不能輸入字母 by john
function pageOnlyNumber(evt){
evt = (evt) ? evt : windowevent;
keyCode = evtkeyCode ? evtkeyCode : (evtwhich ? evtwhich :evtcharCode);
if((keyCode < || keyCode > ) && keyCode != && keyCode != )
{
if(windowevent){

windoweventreturnValue = false;
}
else{
evtpreventDefault();
}
}
}
</script>
<input type="text" id="APPLY_FEE_RATE" name="APPLY_FEE_RATE" onkeypress="pageOnlyNumber(event)" maxlength="" size="" value= class="validate[funcCall[checkFunction]]" />
<input type="text" name="test" id="test" value= />


From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25507.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.