首页 > Web开发 > 详细

jquery函数写法

时间:2014-09-25 13:26:50      阅读:313      评论:0      收藏:0      [点我收藏+]

普通jquery函数写法

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
    var myfunc = {
        aaa: 0,
        init:function(aaa) {
            this.aaa=aaa;
        },
        log:function(msg) {
            if(  (EpBrowser.core=="chrome")  ){//chrome
                console.log("log>>    "+msg);
            }
        }
    };
    myfunc.init("ddddddddd");
    alert(myfunc.aaa);
});
</script>

 

(不确定的参数,初始化及传参)有亮点!!

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
    var Person={
        init : function(option){
            if(typeof option == "undefined"){
                option = {};
            }
            this.aaa = option.aaa || "啊啊啊";
            this.bbb = option.bbb || 25;
            this.ccc = option.ccc || 75;
            this.ddd = (typeof option.ddd != "undefined") ? option.ddd : true;
        },
        showInfo : function(){
            return this.aaa + " " + this.bbb + " " + this.ccc + " " + this.ddd;
        }
    }
    Person.init({
        ccc : 80,
        ddd : "Hank"
    })
    alert(Person.showInfo()); //啊啊啊 25 80 Hank
});
</script>

 

jquery函数写法

原文:http://www.cnblogs.com/qq21270/p/3992430.html

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