日期:2014-05-16  浏览次数:20367 次

IE6 7 8如何通过js修改input的type
我想实现一个显示隐藏密码的功能
代码如下
在IE9 FIREFOX上都正常,但是IE6 7 8无效
请问应该如何实现呢

    <script  type="text/javascript">
        function showPwd() {
            var oCB = document.getElementById("CBShowPwd");
            var oTB = document.getElementById("tbPwd");
            if (oCB.checked == true) {
                oTB.type = "text";
            }
            else {
                oTB.type = "password";
            }
        }
    </script>
IE6 JavaScript js type 兼容

------解决方案--------------------

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
body{font:12px "宋体";}
#aa{cursor:pointer;}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#aa").click(function(){
$("#bb").attr("type","password");
});
});
</script>
</head>
<body>
<div id="aa">改变密码</div>
<input type="text" id="bb">
</body>
</html>


为什么不能用呢????