取text标签的value

来源:互联网 发布:电脑校色软件 编辑:程序博客网 时间:2024/06/05 08:37

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>显示前台页面所有的文本框内容</title>

    <script type="text/javascript">

        function giveValue() {
            var txts = document.getElementsByTagName("input");//得到所有文本框,即得到一个文本框控件数组
            for (var i = 0; i < txts.length; i++) {//遍历input标签数组的长度

                if (txts[i].type=="text") {//如果input标签数组中的元素类型是text
                    alert(txts[i].value);//显示相关text标签的value值
                }
            }
        }
   
    </script>

</head>
<body>

<input type="text" value="123" /> &nbsp &nbsp  <input type="text" value="456" /> &nbsp &nbsp  <input type="text" value="789" />
<br />
<input type="button" value="取值" onclick="giveValue()" />

</body>
</html>