正在做一个在线书签管理的站点,有需要这样一个功能,把匹配节点的id或值拼合起来以用来传递参数

查了一下,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(","));
});

 

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-03-02
  • 2022-02-01
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-08-14
  • 2021-11-30
相关资源
相似解决方案