相关疑难解决方法(0)

当用户单击"显示"链接时,显示密码,再次单击时将其隐藏

我想让这个简单的脚本工作.基本上,当用户单击"显示"链接时,它将在密码文本框中显示密码,并在再次单击时隐藏密码.我已经搜索了解决方案,但找不到任何我需要的东西.这是代码:

JavaScript的

    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)

HTML

<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语句,但仍然没有做任何事情.

html javascript passwords textbox show-hide

16
推荐指数
2
解决办法
5万
查看次数

标签 统计

html ×1

javascript ×1

passwords ×1

show-hide ×1

textbox ×1