gpt4 book ai didi

javascript - 如何查看和隐藏表中所有行的密码

转载 作者:行者123 更新时间:2023-11-28 17:59:31 25 4
gpt4 key购买 nike

Table from the database显示密码功能仅适用于条目的第一行,不适用于接下来的条目/行。 php 使用 foreach 通过数据库显示这些项目。显示/隐藏密码如何适用于所有条目?有任何想法吗??我的代码如下:

HTML:

<td data-title="Password"><input id="viewPass" type="password" value="<?php echo $item["password"]; ?>" readonly/></td>
<button type="button" id="viewPswd" class="btn btn-default"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></button>
<script src="js/showPass.js"></script>

Javascript:

 var myButton = document.getElementById('viewPswd'),
myInput = document.getElementById('viewPass');
myButton.onclick = function () {

'use strict';

if (this.id === 'viewPswd') {
myInput.setAttribute('type', 'text');
this.textContent = 'Hide';

} else {

myInput.setAttribute('type', 'password');

this.id = 'viewPswd';
}
};

最佳答案

如果您想使用多个按钮和文本框,则必须分配 通用的名称或单独的id

您不能为所有元素分配相同的 id。

这里我使用了name属性

var myButton = document.getElementsByName('dynamic');
var myInput = document.getElementsByName('viewPass');
myButton.forEach(function(element, index){
element.onclick = function(){
'use strict';

if (myInput[index].type == 'password') {
myInput[index].setAttribute('type', 'text');
element.firstChild.textContent = 'Hide';
element.firstChild.className = "";

} else {
myInput[index].setAttribute('type', 'password');
element.firstChild.textContent = '';
element.firstChild.className = "glyphicon glyphicon-eye-open";
}
}
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<td data-title="Password">
<input name="viewPass" type="password" value="abcd" readonly/></td>


<button type="button" id="" class="btn btn-default" name="dynamic"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></button>
<br>
<td data-title="Password">
<input name="viewPass" type="password" value="watha" readonly/></td>

<button type="button" id="" class="btn btn-default" name="dynamic"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></button>
<br>

<td data-title="Password">
<input name="viewPass" type="password" value="xyz" readonly/></td>

<button type="button" id="" class="btn btn-default" name="dynamic"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></button>

关于javascript - 如何查看和隐藏表中所有行的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43830318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com