jquery改变input type的值

<input type='hidden' size='8' value='输入'>
使hidden的值变成text

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<style type="text/css">
body{
margin:0px;
background-color: white;
font-family: 'PT Sans', Helvetica, Arial, sans-serif;
text-align: center;
color: #A6A6A6;
}
/*输入框样式,去掉背景阴影模仿原生应用的输入框*/
input{
width: 100%;
height: 50px;
border:none;
padding-left:3px;
font-size: 18px;
}
input:focus {
outline: none;
}
/*显示\隐藏密码图片*/
img{
width: 40px;
height: 25px;
position: absolute;
right: 0px;
margin: 15px;
}
/*登录按钮*/
button{
width: 200px;
height: 50px;
margin-top: 25px;
background: #1E90FF;
border-radius: 10px;
border:none;
font-size: 18px;
font-weight: 700;
color: #fff;
}
button:hover {
background: #79A84B;
outline: 0;
}
/*输入框底部半透明横线*/
.input_block {
border-bottom: 1px solid rgba(0,0,0,.1);
}
/*container*/
#page_container{
margin: 50px;
}
</style>
<script>
$(function(){
$("#demo_img").click(function(){
if($("#demo_input").attr("type")==="password"){
$("#demo_img").attr("src","images/visible.png");
$("#demo_input").attr("type","text");
}
else{
$("#demo_img").attr("src","images/invisible.png");
$("#demo_input").attr("type","password");
}
});
});
</script>
</head>
<body>
<div id="page_container">
<!--密码输入框-->
<div class="input_block">
<img id="demo_img" src="images/invisible.png">
<input type="password" id="demo_input" value="" placeholder="Password"/>
</div>
<button onclick="">Login</button>
</div>
</body>
</html>
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2017-11-24
$("input[type='hidden']").attr(‘type’,'text');
这句话的意思是遍历所有input标签,具体是指type类型为hidden的input标签,然后对它的type属性进行更改 改为:text.
这类表达还长用于多选框中如:
$('.class').find("input[type='checkbox']").attr('checked', 'checked');
能熟记了吧本回答被网友采纳
第2个回答  2017-12-06
在jquery中有一个attr 的方法,他可以改变一个对象的属性的值。具体的写法是$(".a").attr('type','input');
第3个回答  2017-12-06
$("input[type='hidden']").attr('type','text');
第4个回答  2013-10-08
$("input[type='hidden']").attr('type','text');

但是我建议你不要这么来隐藏,你还是通过css样式的display:none 来隐藏
也就是说:

$("input").show();//显示
$("input").hide();//隐藏

其实show()和hide()也是通过改css样式来实现的。
相似回答