gpt4 book ai didi

jQuery 内爆/使用自定义字符(连字符)连接字符串(元素)

转载 作者:行者123 更新时间:2023-12-03 22:19:37 31 4
gpt4 key购买 nike

我选择了 (2) 个元素,通过以下方式选择:

$(this).parents("tr:first").children("td").children("span");

当我这样做时:

$(this).parents("tr:first").children("td").children("span").text();

跨度中的文本(例如a和b)连接在一起(到ab),这几乎就是我想要的

但现在我想通过在(a - b)之间插入连字符(-)来连接它们我已经尝试过这个,但不起作用:

$(this).parents("tr:first").children("td").children("span").join(" - ");

最佳答案

使用$.map:

$.map(
$(this).parents("tr:first").children("td").children("span"),
function(element) {
return $(element).text()
})
.join(" - ");

关于jQuery 内爆/使用自定义字符(连字符)连接字符串(元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5116914/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com