美文网首页
4 jQuery中的each方法

4 jQuery中的each方法

作者: 一枝妖孽 | 来源:发表于2018-05-30 22:17 被阅读0次

4 jQuery中的each方法

//jqury模拟 each 和 size 方法
(function($){
    
    $.fn.mEach= function(callback){
        //次this是 input数组
        var array =$(this);
        for(var i=0;i<array.size();i++){
            callback.apply(array[i]);
        }
    }
    
    $.fn.mSize= function(){
        return this.length;
    }
    
})($);

$().ready(function(){
    $("input").mEach(function(){
        //这个this 是input单个对象
        alert($(this).attr("name"));
    });
    
    alert($("input").mSize());
});

相关文章

网友评论

      本文标题:4 jQuery中的each方法

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