开发者

What are the pros & cons of these kinds of plugins? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

What are the advantages and disadvantages of each one:

 $.fn.hello = function() {  
    $(this).append('<div id="hello">Hello world</div>');
    $(this).delegate('#hello', 'click', function(){
        alert("Hello you clicker");
    });
 } 
$(document).ready(function(){
    $('body'开发者_如何转开发).createHello();
});

Or:

 $.hello= function() {  
    $('body').append('<div id="hello">Hello world</div>');
    $('body').delegate('#hello', 'click', function(){
        alert("Hello you clicker");
    });
 } 

$(document).ready(function(){
    $.createHello();
});

?


The main advantage of that first is that you can use $(this), which you can't use in the second one, so you would have to change it everytime you would want to place it in different location

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜