我不能使用jQuery脚本来管理我的div

0 javascript css jquery

我使用这个jQuery脚本来根据浏览器窗口分辨率来居中我的div.但是我无法让它发挥作用.我在这里错过了什么?

我在jsFiddle中发布了它以便更好地理解这里http://jsfiddle.net/9wvt3/

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}
$(#main).center();
Run Code Online (Sandbox Code Playgroud)

Jar*_*ish 5

这个:

$(#main).center(); 
Run Code Online (Sandbox Code Playgroud)

应该是:

$('#main').center();
Run Code Online (Sandbox Code Playgroud)

请注意,'$()函数的参数.