js 模仿jquery 写个简单的小demo

<div id="div" style="background:red;width:100px;height:300px">
123123123
</div>

<script>
(function (window) {
    function Jquery(arguments) {
        this.obj = document.getElementById(arguments);
    }
    function $(arguments){
        return new Jquery(arguments);
    }
    Jquery.prototype.bgColor = function(arguments){
        this.obj.style.background=arguments;
    };
    Jquery.prototype.fontColor = function(arguments){
        this.obj.style.color=arguments;
    };
    window.Jquery=window.$=$;
})(window)

$('div').bgColor("red");
$('div').fontColor("white");

</script>

 写的都是方法,心中有对象

猜你喜欢

转载自www.cnblogs.com/hellowzd/p/9939173.html