JavaScript js 仿password功能

javascript仿password功能,将用户输入的信息替换成圆点。然后得到用户输入的字符串;当然还有其他的操作需要处理,这里就不一一处理;这里是大致实现的思路和方法。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>filterStr.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> String.prototype.replaceAll = function(s1, s2) { var temp = this; while (temp.indexOf(s1) != -1) { temp = temp.replace(s1, s2); } return temp; } function filter(event, o) { var e = event || window.event; var currentKey = event.keyCode || event.which || event.charCode; var temp = o.value; var filterVal = ""; if (currentKey == 13 || (currentKey > 16 && currentKey < 46) || (currentKey > 112 && currentKey < 123) || currentKey == 144) { //这里需要屏蔽掉一些无输入字符的键,如:回车、shift、alt、Home、delete等;暂时就列举这么多,其他就不一一列举; return; } else if (currentKey == 8) { filterVal = o.getAttribute("filterValue") == undefined ? "" : o.getAttribute("filterValue"); filterVal = filterVal.substring(0, temp.length); o.setAttribute("filterValue", filterVal); } else { var startIndex = temp.lastIndexOf('●'); startIndex = startIndex == -1 ? 0 : startIndex + 1; var val = temp.substring(startIndex, temp.length); filterVal = o.getAttribute("filterValue") == undefined ? "" : o.getAttribute("filterValue"); filterVal += val; o.setAttribute("filterValue", filterVal); var ary = temp.split(''); var result = ""; for (var i = 0; i < ary.length; i++) { if (ary[i] != "●") { result = temp.replaceAll(ary[i], '●'); } } o.value = result; } } function getVal() { alert(document.getElementById("s").getAttribute("filterValue")); } </script> </head> <body> <input type="text" id="s" οnkeyup="filter(event, this)"/> <input type="button" value=" get Value " οnclick="getVal()"> </body> </html>

转载于:https://www.cnblogs.com/javaTest/archive/2010/07/26/2589409.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值