首页 > Web开发 > 详细

jquery设置文本框值 与获取文本框的值

时间:2016-06-25 16:17:06      阅读:133      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="../js/jquery-1.12.4.js"></script>
</head>
<body>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="text"/><br/>
    <input type="button" id="btn1" value="设置"/>
    <input type="button" id="btn2" value="获取"/>
    <script>
        $(function () {
            //设置文本框的值
           $("#btn1").click(function () {
               $("input[type = ‘text‘]").attr("value","文本$");
           });
            //获取文本框的值
            $("#btn2").click(function () {
                //定义一个空数组
                var value1 = [];
                for(var i =0;i<$("input[type = ‘text‘]").length;i++){
                    //找到每一个input  这里input是dom对象
                    var input = $("input[type = ‘text‘]")[i];
                    //用$(input)将它转换成jquery对象  使用attr()方法 获取值 追加到数组中去
                    value1.push($(input).attr("value"));
                }
                console.log(value1.join("|"));

            });
        });
    </script>
</body>
</html>

 

jquery设置文本框值 与获取文本框的值

原文:http://www.cnblogs.com/lcf1314/p/5616343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!