Home > Web Front-end > JS Tutorial > Add implementation code of join method to jQuery_jquery

Add implementation code of join method to jQuery_jquery

WBOY
Release: 2016-05-16 18:15:04
Original
1343 people have browsed it

After checking, jquery has no direct method,

, but there is a map method, which is very simple to define a method to implement this function

Copy the code The code is as follows:

jQuery.fn.join = function(sep,mapvalue){
return $.map(this,mapvalue).join (sep);
};
jQuery.fn.joinattr = function(sep,attr){
return this.join(sep,function(item){return $(item).attr(attr) ;});
};
jQuery.fn.joinvalue = function(sep){
return this.join(sep,function(item){return $(item).val();}) ;
};

When using
Copy the code The code is as follows:

$("#getid").click(function(){
alert($("input").joinattr(",","id"));
});
$("#getvalue").click(function(){
alert($("input").joinvalue(","));
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template