封装Js库从获取控件的value值开始

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" >
        function show() {
            var _value = document.getElementById("text_1").value;
            alert(_value);
        }

        function show2() {
            alert(getValue("text_1"));
        }
        function getValue(id) {
            var _value = document.getElementById(id).value;
            return _value;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input id="btn_1"  type="button" onclick="show()" value="点击我获取Value值" />
    
    <input  id="text_1" type="text" value="测试数据"/>
    <input id="btn_2" type="button"  onclick="show2()" value="封装方法" />
    </div>
    </form>
</body>
</html>

show()和show2()方法的效果是一样的。

原文地址:https://www.cnblogs.com/ITyueguangyang/p/4315078.html