两个文本框的值添加后自动获取值

1,获取所些文本框的值

 1 <script>
 2         function show() {
 3             var a1 = document.getElementById("a1");
 4             var a2 = document.getElementById("a2");
 5             var show = document.getElementById("show");
 6             show.innerHTML = "a1的值是:" + a1.value + "; a2的值是: " + a2.value;
 7         }
 8     </script>
 9  <input name="a1" type="text" id="a1" onchange="show()" />
10     <input name="a2" type="text" id="a2" />
11     <input type="button" name="Submit" value="按钮" onclick="show();" />
12     <div id="show"></div>

2,若是求两数之集的话

<script>
    function show() {
        var a1 = document.getElementById("a1");
        var a2 = document.getElementById("a2");
        var a3 = document.getElementById("a3");
        a3.value = a1.value * a2.value;
       
    }
</script>
body中写
  <input name="AWprice" type="text" id="a1"  /> <input name="AddWareNumber" type="text" id="a2" onchange="show()" /> <input id="a3" type="text" name="AWMoney" />

效果图

posted @ 2016-08-12 20:02  大黄人  阅读(217)  评论(0编辑  收藏  举报