现在的位置: 首页 > 综合 > 正文

js 通过 this 传 id

2013年12月01日 ⁄ 综合 ⁄ 共 489字 ⁄ 字号 评论关闭

    <script type="text/javascript">
        function btn(a) {
            alert(a
);                          //   a相当于 document.getElementById('txt1')


            var max= 9;
            var min = 0;
            if (a.value >= min && a.value <= max) {

               a.style.backgroundColor = "red";
            }

        }
    </script>

<body>
    <form id="form1" runat="server">
    <div>
     <input type="text" runat="server"  onchange="btn(this)" 
id="txt1" />          

  //this相当于 document.getElementById('txt1')


    </div>
    </form>
</body>

抱歉!评论已关闭.