<input id="target" style="ime-mode:disabled;" onpaste="return false" type="text"/>// style="ime-mode:disabled;" 禁止输入法 onpaste="return false"禁止黏贴
//只允许输入数字
$("#target").keydown(function(e){
var e= e||event;var code = e.keyCode||e.which||e.charCode;;//(String.fromCharCode(e.which));//转换成实际值
var flag = !e.ctrlKey &&!e.shiftKey &&!e.altKey;
if(e.altKey){
e.returnValue = false;
e.keyCode = 0;
return false;
}
if((flag && code >= 96 && code <= 105) || code == 8 || (flag && code >= 48 && code <= 57)){
return true;
}
return false;
}).keyup(function(e){
handelInputVal($(this));
});
function handelInputVal(_this){
var val = $.trim($(_this).val());
var tmp ="";
for(i=0;i<val.length;i++){
if(val[i]>=0&&val[i]<=9&&val[i]!=" "){
tmp += val[i];
}
}
if(tmp.length==0)
tmp = $(_this).attr("defaultVal");
$(_this).val(tmp);
}