我想让这个简单的脚本工作.基本上,当用户单击"显示"链接时,它将在密码文本框中显示密码,并在再次单击时隐藏密码.我已经搜索了解决方案,但找不到任何我需要的东西.这是代码:
function toggle_password(target){
var tag = getElementById(target);
var tag2 = getElementById("showhide");
if (tag2.innerHTML == 'Show'){
tag.setAttribute('type', 'text');
tag2.innerHTML = 'Hide';
}
else{
tag.setAttribute('type', 'password');
tag2.innerHTML = 'Show';
}
}
Run Code Online (Sandbox Code Playgroud)
<label for="pwd0">Password:</label>
<input type="password" value="####" name="password" id="pwd0" />
<a href="#" onclick="toggle_password('pwd0');" id="showhide">Show</a>
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,没有任何反应.我已经测试了这个,没有使用if语句,但仍然没有做任何事情.