JQuery中如何动态修改input的type属性


代码如下:

 1     jQuery(".member_id").focus(function() { 
 2       jQuery(this).val('');
 3     }).blur(function() { 
 4         
 5       if(jQuery(this).val() == "") { jQuery(this).val("账号"); }
 6     });
 7 
 8     jQuery(".member_passwd").focus(function() { 
 9       jQuery(this).val('');
10      document.getElementById("member_passwd").type="password";
11        //jQuery(this).attr('type','password');
12     }).blur(function() { 
13         
14       if(jQuery(this).val() == "") { jQuery(this).val("密码");  document.getElementById("member_passwd").type="text"; }
15     });
16 
17 
18 }); 

 

以上代码注释部分会报错,提示“type property can't be changed ”,初步结论JQuery中的attr()方法不可以修改input的type属性。

 

此段代码在IE,chrome、FireFox中均能正常使用。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM