美文网首页
jquery中$.each()、$().each(functio

jquery中$.each()、$().each(functio

作者: krystal_H | 来源:发表于2019-09-24 22:06 被阅读0次

    $.each()数组jsonDOM结构等的遍历,
    $().each(function(i){}),只能遍历jQuery对象

    <input name="aaa" type="text" value="111" />
    <input name="bbb" type="text" value="222" />
    <script src="./jquery.min.js"></script>
    <script>
        $(function () {
          $("input:text").each(function (i, val) {  
          //第一个参数表示索引下标,第二个参数表示当前索引元素
            console.log(i, val);
            console.log(val.name);
            console.log(val.value);
          });
        })
    </script>
    

    也可以,

    $.each($("input:text"),function (index, item) {})
    

    相关文章

      网友评论

          本文标题:jquery中$.each()、$().each(functio

          本文链接:https://www.haomeiwen.com/subject/tlwbuctx.html