功能:
用户使用USB扫描仪扫描ID,捕获ID号(8个字符)并将值输入到<input type=password>
中 field 。但是,不会显示捕获的 ID 值的所有 8 个要点,而是仅其中 5 个字符是密码类型,其余 3 个字符将采用文本格式。
问题:
我尝试过在线搜索,但似乎找不到任何可能的建议或解决方案。我已将输入字段类型设置为密码,因此此时该字段中的所有值都是密码类型格式。
但是,我想要实现的是前 5 个字符遵循密码类型格式,而其余 3 个字符采用文本类型格式。
我现在取得的成就:
......
我希望实现的目标:
.....12A
我想请求帮助或为我指明任何方向,以便我能够继续下去。
谢谢。
<input type="password" id= "NRICCodeField" style="position:absolute; top:545px; left:690px; height:68px; width:545px; outline: 0; border: 0; font-size:70px; font-color:#765725; font-family:'Gothic'; background: transparent; z-index:100;" autofocus src="lib/image/transparent.png">
最佳答案
我已经为您找到了一种方法,如果它适合您,您可以查看下面的代码。您需要一个代理隐藏字段,您应该在其中存储实际值,并且文本字段将仅显示给用户查看。当提交表单时,您应该从隐藏字段而不是文本字段中选择数据。
<!DOCTYPE html>
<html class="not-ie" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>41160278</title>
<script type="text/javascript">
function applyFormat(self){
var input = self.value;
var firstPart = input.substr(0,4);
var lastPart = input.substr(5, input.length);
formname.forShow.value = firstPart.replace(firstPart, '*****') + lastPart;
formname.forStore.value = input;
}
</script>
</head>
<body>
<form action="#" name="formname">
<fieldset>
<input type="text" name="forShow" maxlength="8" onchange="applyFormat(this)" value="" />
<input type="hidden" name="forStore" value="" />
</fieldset>
</form>
</body>
</html>
关于javascript - 显示 8 字符密码格式中的 3 个文本字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41160278/