导航

IE中如何替换控件type属性的方法

Posted on 2012-02-29 10:43  漂泊一生  阅读(271)  评论(0编辑  收藏  举报

1.IE中密码输入无法替换type的解决方法

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function onfocuspwd(obj, otherObj) {
            obj.hide();
            otherObj.show();
            otherObj.focus();
        }
        function onblurpwd(otherObj, obj) {
            if (otherObj.val().length == 0) {
                otherObj.hide();
                obj.show();
            }
        }
    </script>
</head>
<body>
        <input id="txtPassword" type="text" value="输入密码" onfocus="onfocuspwd($(this),$('#txtPwd'));" />
        <input id="txtPwd" type="password" style="display: none" onblur="onblurpwd($(this),$('#txtPassword'))" />
</body>
</html>

 

2.不需要获取焦点的替换方式

            var obj = document.getElementById("radio");
            obj.outerHTML = obj.outerHTML.replace(/type=(?:"[^"]+"|'[^']+'|[^"' >]+)/i, "type='checkbox'");