开发者

jQuery very simple plugin

I have created my firs plugin with jquery and it simply dont work as it should.

Can someone please correct me, and if possible send me to some jQuery tutorials?

Im trying to grab label value and pass it to another input

jQuery.fn.checktoclient = function () {
return this.each (function () {

this.map(function(){

        return $(this).text()

    }).get();

});
};
var radio1_val = $('input[name="form[radio1]"开发者_运维问答]:checked + label').checktoclient();

$('input#radioclient').val(radio1_val);

May thanks for your help.

Dom


Take a look at the jQuery plugin Getting started itself:

  • http://docs.jquery.com/Plugins/Authoring

In the The Basics part, you have a plugin function maxHeight that does exactly what you want, except that it doesn't return the text, but height. I suggest you read it - there are a few other things that you should be doing, summarized at the end, so it will be useful.

Btw, the reason it is not working is because .each() returns the jQuery itself, so your function is returning the jQuery object, not the text you were expecting - look at the Returns on the .each() API documentation:

  • http://api.jquery.com/each/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜