计算器的退格键点击实现删除字符文字
2017-06-30 17:17
267 查看
一、首先写个例子,点击退格实现删除文本框的字符文字:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>退格删除</title>
</head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
function del(){
var s2 = $("#test").val();
s2 = s2.substring("",s2.length-1);
s2 = (s2 == "" ? "" : s2);
$("#test").val(s2);
}
</script>;
<body>
<input type="text" id="test" />
<input type="button" onclick="del()" value="退格" />
</body>
</html>
二、计算器的退格键点击实现删除字符文字:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>退格删除</title>
</head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
function del(){
var s2 = $("#test").val();
s2 = s2.substring("",s2.length-1);
s2 = (s2 == "" ? "" : s2);
$("#test").val(s2);
}
</script>;
<body>
<input type="text" id="test" />
<input type="button" onclick="del()" value="退格" />
</body>
</html>
二、计算器的退格键点击实现删除字符文字:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>退格删除</title> <style> .myinput{ width:70px; height:30px;} .tf{ width:220px; height:30px; margin-bottom:5px; font-size:26px; font-family:Tahoma, Geneva, sans-serif; color:#fff; border:2px solid #999; background:#000; text-align:right;} } </style> </head> <script type="text/javascript"> window.onload = function(){ var tf = $("tf"); for( var i=0;i<11;i++ ){ $("btn"+i).onclick = function(){ if(this.value == "." && tf.value == "") return false; if(this.value == "." && tf.value.indexOf(".") != -1) return false; if(tf.value == "0"){ if(this.value == "."){ tf.value += this.value; } }else{ tf.value += this.value; } } } $("back").onclick = function(){ tf.value = tf.value.replace(/.$/,'') } } function $(id){return document.getElementById(id);} </script> <body> <input class="tf" name="textfield" type="text" id="tf" size="30" /> <br /> <input class="myinput" type="submit" name="button" id="btn0" value="0" /> <input class="myinput" type="submit" name="button" id="btn1" value="1" /> <input class="myinput" type="submit" name="button" id="btn2" value="2" /> <br /> <input class="myinput" type="submit" name="button" id="btn3" value="3" /> <input class="myinput" type="submit" name="button" id="btn4" value="4" /> <input class="myinput" type="submit" name="button" id="btn5" value="5" /> <br /> <input class="myinput" type="submit" name="button" id="btn6" value="6" /> <input class="myinput" type="submit" name="button" id="btn7" value="7" /> <input class="myinput" type="submit" name="button" id="btn8" value="8" /> <br /> <input class="myinput" type="submit" name="button" id="btn9" value="9" /> <input class="myinput" type="submit" name="button" id="btn10" value="." /> <input class="myinput" type="submit" name="button" id="back" value="退格" /> </body> </html>
相关文章推荐
- js实现模拟计算器退格键删除文字效果的方法
- js实现模拟计算器退格键删除文字效果的方法
- [Rcode]实现文字包含某一字符的批量替换和删除
- 实现网页文本框显示灰色提示文字且点击后消失的一个小函数(基于jquery)
- dojo grid遇到的问题 点击按钮“全选”'删除"无法实现
- 要求:把“内容”中与 ”标题“一样的文字批量删除了,如何用sql语句实现
- CSS+JS实现点击文字弹出定时自动关闭的DIV层菜单
- Windows 界面:具有“删除元素”和“按列进行字符比较排序”的 CListCtrol 继承类 CListCtrolEx 的实现
- jquery实现文字显隐并改变点击时候的字
- 不用ajax实现点击文字即可编辑的方法
- word文字编辑时在中间插入文字时自动删除或覆盖了后面一个字符
- 点击文字链接弹出确认框基于js Confirm实现
- 怎么实现点击textbox后textbox里用于提示的文字消失
- 不使用js实现点击文字选中radio
- jquery实现文字显隐并改变点击时候的字
- jQuery 实现点击文字放大效果
- 字符串s中出现的C字符删除的不同实现方法
- 不用ajax实现点击文字即可编辑的方法
- JTable选择一行,输入数字,自动向前移动一位,点击退格键,删除最后一个数字
- 用JS来实现输入框提示文字点击时消失