码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-06-18 10:57:07      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

代码如下:

 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中均能正常使用。

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

标签:

原文地址:http://www.cnblogs.com/BBCaroline/p/4585013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!