查了一下,jquery没有直接的方法, 不过有一个map方法,使用它很简单就可以定义一个实现该功能的方法 复制代码 代码如下: 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();}); }; 使用的时候 复制代码 代码如下: $("#getid").click(function(){ alert($("input").joinattr(",","id")); }); $("#getvalue").click(function(){ alert($("input").joinvalue(",")); });
推荐阅读
jquery 学习之二 属性(类)
addClass(class)
为每个匹配的元素添加指定的类名。
Adds the specified class(es) to each of the set of matched elements.
返回值
jQuery
参数
class (String) : 一个或多个要添加到元素中的CSS类名,请用空格分>>>详细阅读
本文标题:为jQuery增加join方法的实现代码
地址:http://www.17bianji.com/kaifa2/JS/25341.html
1/2 1