标签:
<HTML>
<HEAD>
<TITLE>键盘隐藏</TITLE>
<script src="http://www.u160.com/Js/jquery-1.4.4.min.js" type="text/javascript"></script>
<style>
input{ height:30px; line-height:30px; width:160px; text-indent:0.4em}
</style>
</HEAD>
<BODY style="background:#eee;">
<input class="t1 imUn" type="text" value="123" />
<input class="t2 imUn" type="text" value="456" />
<hr />
<input class="t" type="text" value="888" />
<span>删除</span>
<div id="log" style="background:#fff;padding:5px;"></div>
<script>
/*
$("#t").bind("focus",function(){
//app.closeKey();
setTimeout(function(){
app.closeKey();
},10)
});
*/
var kpObj=null;
function kpInput(v){
if(kpObj){
var o=kpObj;
var val=o.val();
((!val.replace("-","").length)||(kpObj[0].selectionStart==0 )) &&(v==".")&&(v="0.");//.替换成0. val.indexOf(".")<0 &&
kpiget();
if(v=="-"||v=="0."){//只出现在最前方 或光标最前方
(!val.length)&&o.val(v)&& kpiset(-v.length);
(val.length)&&(val.indexOf(v)<0 && kpObj[0].selectionStart==0) && o.val(v+o.val()) && kpiset(-v.length);
}else
if(!isNaN(v)||v=="."){
//o.val(val+""+v);
kpInsert(v);
}else{
if(v=="DEL"){
o.val(val.substr(0,val.length-1));
}else
if(v=="完成"){
o.blur();
}
}
var l=o.val().length;
o.val()=="00" && o.val(0);//解决00开始
o.val(o.val().replace(".","$#$").replace(/\./g,"").replace("$#$","."));//.只出现一次
kpiset(l-o.val().length)
}
}
function kpInsert(t){
var i=kpObj[0].selectionStart;
var v=kpObj.val();
kpObj.val(v.substr(0,i)+t+v.substr(i,v.length-i));
kpi=i+1;
}
var kpi=0;
function kpiget(){
kpi=kpObj[0].selectionStart;
}
function kpiset(val){
kpObj[0].selectionStart=kpi-val;
kpObj[0].selectionEnd=kpi-val;
kpi=kpi-val;
}
var isbs=false
function kpBackSpace(){
if(isbs) return;
isbs=true;
var o=kpObj[0];
if(o){
var i=o.selectionStart;//非IE
$(o).val($(o).val().substr(0,i-1)+$(o).val().substr(i,$(o).val().length-i));
o.selectionStart=i-1;
o.selectionEnd=i-1;
}
isbs=false;
}
function log(txt){
$("#log").html($("#log").html()+"<br />"+txt);
}
$(".imUn").live("focus",function(){
kpObj=$(this);
app.keybHide();
}).live("blur",function(){
objKeypad=null;
app.keybShow();
var v=$(this).val()
.replace(/[^\d.-]/g,"")//去掉非.-数字
.replace(/^[0\.-]{1,}$/g,"0");//-0.000 替换成0
v.length && (v=v.substr(0,1)+v.substr(1).replace(/-/g,"")); //去除不在最前面的-
v!=""
&&(v=Number(v.replace(".","$#$").replace(/\./g,"").replace("$#$",".")));
$(this).val(v);
})
$("span").click(function(){
$(".t2").remove();
}
);
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>键盘隐藏</TITLE>
<script src="http://www.u160.com/Js/jquery-1.4.4.min.js" type="text/javascript"></script>
<style>
input{ height:30px; line-height:30px; width:160px; text-indent:0.4em}
</style>
</HEAD>
<BODY style="background:#eee;">
<input class="t1 imUn" type="text" value="123" />
<input class="t2 imUn" type="text" value="456" readonly="readonly" />
<hr />
<input class="t" type="text" value="888" />
<div id="log" style="background:#fff;padding:5px;"></div>
<div style="height:30px; line-height:30px; background#fefefe; position:absolute;bottom:0;">bottom</div>
<script>
var keypad={
obj:null,
ki:0,//光标位置
kiGet:function(){
this.ki=this.obj[0].selectionStart;
},
kiSet:function(i){
this.ki=this.ki-i;
this.obj[0].selectionStart=this.ki;
this.obj[0].selectionEnd=this.ki;
},
insert:function(t){
var i=this.obj[0].selectionStart;
var v=this.obj.val();
this.obj.val(v.substr(0,i)+t+v.substr(i,v.length-i));
this.ki=i+1;
},
back:function(){
var o=this.obj[0];
if(o){
var i=o.selectionStart;//非IE
$(o).val($(o).val().substr(0,i-1)+$(o).val().substr(i,$(o).val().length-i));
o.selectionStart=i-1;
o.selectionEnd=i-1;
}
},
input:function(v){
var o=this.obj;
if(o){
log("1");
var val=o.val();
((!val.replace("-","").length)||(o[0].selectionStart==0 )) &&(v==".")&&(v="0.");//.替换成0. val.indexOf(".")<0 &&
log("2");
this.kiGet();
if(v=="-"||v=="0."){//只出现在最前方 或光标最前方
log("3");
(!val.length)&&o.val(v)&& this.kiSet(-v.length);
(val.length)&&(val.indexOf(v)<0 && o[0].selectionStart==0) && o.val(v+o.val()) && this.kiSet(-v.length);
}else
if(!isNaN(v)||v=="."){
log("04");
this.insert(v);
log("05");
}else{
if(v=="DEL"){
o.val(val.substr(0,val.length-1));
}else
if(v=="完成"){
o.blur();
}
}
log("6");
var l=o.val().length;
o.val()=="00" && o.val(0);//解决00开始
o.val(o.val().replace(".","$#$").replace(/\./g,"").replace("$#$","."));//.只出现一次
this.kiSet(l-o.val().length)
}
}
}
function log(txt){
android&&android.webLog(txt);
//$("#log").html($("#log").html()+txt);//+"<br />"
}
$(".imUn").live("focus",function(){
keypad.obj=$(this);
android.keybHide();
}).live("blur",function(){
log("blur");
keypad.obj=null;
android.keybShow();
var v=$(this).val()
.replace(/[^\d.-]/g,"")//去掉非.-数字
.replace(/^[0\.-]{1,}$/g,"0");//-0.000 替换成0
v.length && (v=v.substr(0,1)+v.substr(1).replace(/-/g,"")); //去除不在最前面的-
v!=""
&&(v=Number(v.replace(".","$#$").replace(/\./g,"").replace("$#$",".")));
$(this).val(v);
})
$(function(){
alert(0;)
})
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>键盘隐藏</TITLE>
<script src="http://www.u160.com/Js/jquery-1.4.4.min.js" type="text/javascript"></script>
<style>
input[type=text]{ height:30px; line-height:30px; width:160px; text-indent:0.4em}
input[type=button]{ height:30px; line-height:30px;}
</style>
</HEAD>
<BODY style="background:#eee;">
<input class="t1 imUn" type="text" value="123" />
<input class="tt" type="button" value="处理" />
<script>
$(".tt").click(function(){
//$(".t1").val($(".t1").val().replace(/[^\d.-]/g,""));
//去掉结尾
//$(".t1").val($(".t1").val().replace(/\.$/g,""));
//去开头的0
//$(".t1").val($(".t1").val().replace(/^0*./g,"")); //n0.替换掉0
//$(".t1").val($(".t1").val().replace(/^\./g,"0."));
//alert((/^[0\.-]{1,}$/g).test($(".t1").val()));
var v=$(".t1").val()
.replace(/[^\d.-]/g,"")//去掉非.-数字
.replace(/^[0\.-]{1,}$/g,"0");//-0.000 替换成0
v.length && (v=v.substr(0,1)+v.substr(1).replace(/-/g,"")); //去除不在最前面的-
v!=""
&&(v=Number(v.replace(".","$#$").replace(/\./g,"").replace("$#$",".")));
$(".t1").val(v);
/*
v!="0"
&&(
v=v
.replace(/\.$/g,"")//去掉末尾的.
.replace(/^0{1,}\./g,".")//先替换n0.的
.replace(/^0{1,}/g,"")//再替换开头为n个0(不然 0. 变成 .开头)
.replace(/^\./g,"0.")//修复.为0.
)
var v=$(".t1").val();
v=v.replace(v.substr(1),v.replace(/-/g,""))
$(".t1").val(v);
*/
});
</script>
</BODY>
</HTML>
标签:
原文地址:http://www.cnblogs.com/hack0573/p/5661129.html