android js 類比鍵盤

來源:互聯網
上載者:User

標籤:

<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);}elseif(!isNaN(v)||v=="."){   //o.val(val+""+v);   kpInsert(v);}else{   if(v=="DEL"){o.val(val.substr(0,val.length-1));   }elseif(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=falsefunction 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);}elseif(!isNaN(v)||v=="."){   log("04");   this.insert(v);   log("05");}else{   if(v=="DEL"){o.val(val.substr(0,val.length-1));   }elseif(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>

  

android js 類比鍵盤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.