使用javascript和chechbox更改输入类型,如何?
我想创建一个注册表,可以隐藏和显示密码输入。我试过这个(JS): 表格:使用javascript和chechbox更改输入类型,如何?,javascript,html,input,Javascript,Html,Input,我想创建一个注册表,可以隐藏和显示密码输入。我试过这个(JS): 表格: SQL主机: SQL adatbázis: SQL Felhasznaáló: SQL jelszó: 我想这样做: 如果选中复选框,则密码输入类型为文本。未选中时,密码类型为password。。。我写了这个JavaScript,但不起作用-(使用.checked查看是否选中了复选框,而不是值 HTML: 注意:IE中不支持动态更改输入类型。IE9中@jbabey可以正常工作。IE是piggeon c*ap…:-D我
SQL主机:
SQL adatbázis:
SQL Felhasznaáló:
SQL jelszó:
我想这样做:
如果选中复选框,则密码输入类型为文本。未选中时,密码类型为password。。。我写了这个JavaScript,但不起作用-(使用
.checked
查看是否选中了复选框,而不是值
HTML:
注意:IE中不支持动态更改输入类型。IE9中@jbabey可以正常工作。IE是piggeon c*ap…:-D我不使用它们…但这就是我想要的。。。
function showhide(melyik,hol) {
var melyiket = document.getElementById(melyik);
var melyikkel = document.getElementById(hol);
if (melyikkel.value == '1') {
document.getElementById(melyikkel).value='0';
document.getElementById(melyiket).type='password';
} else {
document.getElementById(melyikkel).value='1';
document.getElementById(melyiket).type='text';
}
}
<div style="margin-top:20px;">
<p>SQL host: <input type="text" name="sql_host" value="localhost"/></p>
<p>SQL adatbázis: <input type="text" name="sql_db"/></p>
<p>SQL felhasználó: <input type="text" name="sql_user"/></p>
<p>SQL jelszó: <input type="text" name="sql_password" id="sql_password"/>
<input type="checkbox" name="show_password_1" id="show_password_1" value="0" onclick="showhide('sql_password','show_password_1');">
</p>
</div>
<input type="password" name="pwd" id="pwd" />
<input type="checkbox" name="show" id="show" onclick="showhide('pwd','show');">
function showhide(pwd,show)
{
var epwd = document.getElementById(pwd);
var eshow = document.getElementById(show);
epwd.type = eshow.checked ? 'text' : 'password';
}