开发者

What does this line of JQUERY mean?

I would like to add the jQuery OpenID Plug-in in my webpage.

Actually i would like to add it into a content page of a MasterPage

$(function () { $("form.openid:eq(0)").openid(); });

But something goes terribly wrong, and the Javascript code is never executed.

I guess this has to do with the fact that my page renders as follows

<form id="form1" runat="server">
...
</form>

and here comes a part of Javascript called

//jQuery OpenID Plugin 1.1
//Copyright 2009 Jarrett Vance http://jvance.com/pages/jQueryOpenIdPlugin.xhtml
$.fn.openid = function() {
  var $this = $(this);
  var $usr = $this.find('input[name=openid_username]');

and the Jquery as follo开发者_如何学Cws

 $(function () { $("form.openid:eq(0)").openid(); });

So what does the line above mean?


$(function () { 
   $("form.openid:eq(0)").openid();  
});

Can be broken down to this...

   $(function () { 

    });

Simply means call the inner function once the page is loaded.

$("form.openid:eq(0)").openid();

Means call the method openid() on the first instance of a form with the cssclass openid.


It means get the first form element has class "openid" then run openid() function


It invokes the method openid() on the first (eq(0)) form-tag with a css class named "openid" It doesn't get executed since you miss class="openid" on your form-tag


Try this instead:

$(function () { $("form:eq(0)").openid(); });

Your code will look for the first form element whose class attribute is set to "openid".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜