Jquery 递归选择器

发布于 2024-08-25 14:48:20 字数 328 浏览 2 评论 0原文

我有一大堆

。我想要做的是遍历所有 .productlistname 并截断文本并用截断的版本替换当前文本。

这是我到目前为止所得到的:

$(".productlistname a").html($(".productlistname a").html().substring(0,10));

这只是截断第一个,并将 .productlistname 的其余部分替换为第一个的截断版本。

I have whole bunch of <div class="productlistname"><a href="#">The Text!</a></div>. What I want to do go through all .productlistname and truncate the text and replace the current text with the truncated version.

Here is what I have so far:

$(".productlistname a").html($(".productlistname a").html().substring(0,10));

This just truncate the first one and replaces the rest of .productlistname with the truncated version of the first one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尴尬癌患者 2024-09-01 14:48:20
$(".productlistname a").each(function () {
    $(this).html($(this).html().substring(0,10));
});
$(".productlistname a").each(function () {
    $(this).html($(this).html().substring(0,10));
});
情何以堪。 2024-09-01 14:48:20
$(".productlistname a").each(function() {
  $(this).html($(this).html().substring(0,10));
});
$(".productlistname a").each(function() {
  $(this).html($(this).html().substring(0,10));
});
挽心 2024-09-01 14:48:20
$(".productlistname a").each(functon(){
  // loopy loop
});
$(".productlistname a").each(functon(){
  // loopy loop
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文