使用onclick函数将JavaScript值连续输入到密码输入中
Continuously input JavaScript values into password entry with onclick function?
如何使用javascript onclick函数在密码字段中连续输入密码值?
我有两个"蓝色"answers"红色"图像,它们与onclick函数一起使用,并且具有以下值;
Blue= w3!
Red= T4.
当我点击蓝色图像时,它会输入值"w3!"输入密码字段。但当我点击红色图像时,它会替换输入,并在密码字段中变为"T4"。如何将红色输入与蓝色输入连接起来,使其成为'w3!T4’,而不是替换它?求你了,我这里需要帮助。。。thx。以下是我的代码条目:
<!DOCTYPE html>
<html>
<head>
<style>
# red
{width:50px;
height:50px;
}
# blue
{width:50px;
height:50px;
}
</style>
<script src="javascript/myred.js"></script>
<script src="javascript/myblue.js"></script>
</head>
<body>
<img id="red" src="images/items/blue_in.jpg" alt="no blue" onclick="myblue()">
<img id="blue" src="images/items/red_in.jpg" alt="no red" onclick="myred()">
<label for="password">Passcode:</label>
<input name="password" type="password" id="password">
</body>
</html>
我的服务器中存储的JavaScript文件如下所示;
对于myblue:
function myblue()
{
x=document.getElementById("password"); // Find the element
x.value="w3!"; // add the content
}
对于myred:
function myred()
{
x=document.getElementById("password"); // Find the element
x.value="T4"; // add the content
}
请问,我如何在不替换红色输入的情况下将蓝色图像的值添加到密码字段中。。。干杯欢迎评论。。
使用+=
function myblue()
{
x=document.getElementById("password"); // Find the element
x.value += "w3!"; // add the content
}
function myred()
{
x=document.getElementById("password"); // Find the element
x.value += "T4"; // add the content
}
function myblue()
{
x=document.getElementById("password"); // Find the element
x.value += "w3!"; // add the content
}
当然,该解决方案会附加字符串,表示它可能是"w3!w3!w3!T4!",具体取决于您单击它的频率。
function myblue()
{
x=document.getElementById("password"); // Find the element
if(x.value.indexOf('w3!') < 0){
x.value += "w3!"; // add the content
}
}
如果只需要一次值,请使用此方法。当然,您必须更改此函数才能用作myred()
相关文章:
- 密码输入键脚本在首次使用后无法工作
- AngularJs Cordova安卓应用程序中输入的4位密码PIN验证
- 在每个字符输入后,使密码文本框值可见
- 如何使输入类型=“;电话“;按类型工作=“;密码”;
- 密码输入启动 JavaScript
- 使用复选框切换密码输入(由于安全风险而不起作用)
- 密码输入不起作用的Javascript模糊
- 如何将此文本输入文本更改为密码输入?拉拉维尔
- 输入密码后的JavaScript简单重定向
- 如何提示用户在 HTML/JS 中输入密码,让他们无法在页面源代码中找到密码
- 检查输入类型并在单击保存时跳过输入“密码”字段
- 在密码文本框中输入密码后,应触发回车键
- 输入(密码)onblr javascript bug internetexplorer 7和8
- 如何知道输入密码字段的值
- 如何使用JAVA自动输入密码并登录无线路由器
- 输入密码字段-用图像代替符号
- 记住输入密码对话框,无需重新加载页面
- 登录表单无法识别chrome上的输入密码
- 输入密码字段的默认文本
- 使用nodejs Telnet登录时不能输入密码