修改input的type属性的几种方法

来源:互联网 发布:数据库查重复数据 编辑:程序博客网 时间:2024/06/05 03:13
  • 通过js直接改,在IE9以下是不行的。
  • 通过jquery的attr方法修改,在IE9以下也是不行的。
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>修改type属性</title>        <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>        <script type="text/javascript">            function change(){                document.getElementById("password").type = "password";            };            $(function(){                $(".btn").click(function(){                    $("#demo2").attr("type","password");                });                $(".btn02").click(function(){                    $(".demo3").replaceWith('<input type="password" name="demo3" id="demo3" value="" /> <button class="btn02">通过replace方法修改</button>');                })            });        </script>    </head>    <body>        <div class="js">            <input type="text" name="password" id="password" value="" />            <button id="changeType" onclick="change()">通过js修改</button>        </div>        <div class="jquery">            <input type="text" name="demo2" id="demo2" value="" />            <button class="btn">通过jqurey修改</button>        </div>        <div class="demo3">            <input type="text" name="demo3" id="demo3" value="" />            <button class="btn02">通过replaceAll方法修改</button>        </div>    </body></html>
原创粉丝点击