Jquery:选择带有“包含”的完整 href方法

发布于 2024-09-18 01:34:55 字数 888 浏览 5 评论 0原文

是否可以使用 jQuery 选择一个 href 包含另一个变量的完整链接?

我的代码是:

var element1 = $(".not-viewed").parents('li').attr("id");

var element2 = $(".videoTitle").attr("href");

我需要选择包含“element1”的完整链接,因为页面中有多个视频。在我的代码中选择页面上的第一个,但我需要带有 id 的特定链接。 示例..[在此示例中,我需要的代码是:1581889025]

    <li class="videoContainer vidLink" id="1581889025">
    <a href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">
    <span class="HOVER"></span>
    <div class="videoX"><img id="clThumb_1581889025" src="PREVIEW.jpg">
    </div>  </a>
    <a class="videoTitle" href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">Title of Video</a>
<span class='not-viewed'></span>
<div class="tooltip-footer"></div>
</li>

提前致谢。 亲切的问候。

Is it possible using jQuery to select one full link which href contains another variable?

My code is:

var element1 = $(".not-viewed").parents('li').attr("id");

var element2 = $(".videoTitle").attr("href");

Where i need to select a full link that contains 'element1',because there several videos in the page.In my code select the first on the page,but i need the specific with id..
Example..[In this example the code that i need is: 1581889025]

    <li class="videoContainer vidLink" id="1581889025">
    <a href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">
    <span class="HOVER"></span>
    <div class="videoX"><img id="clThumb_1581889025" src="PREVIEW.jpg">
    </div>  </a>
    <a class="videoTitle" href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">Title of Video</a>
<span class='not-viewed'></span>
<div class="tooltip-footer"></div>
</li>

Thanks in advance.
Kind regards.

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

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

发布评论

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

评论(1

往日 2024-09-25 01:34:55

您可以使用属性包含选择器(*=),像这样:

var id = $(".not-viewed").parents('li').attr("id");
var href = $(".videoTitle[href*='" + id + "']").attr("href");

您可以在这里尝试一下,您可能还需要$(".videoTitle[href*='/" + id + ":']") 将其范围缩小到 /1581889025: 匹配项,以防存在 例如 15818890250

You can use the attribute-contains selector (*=), like this:

var id = $(".not-viewed").parents('li').attr("id");
var href = $(".videoTitle[href*='" + id + "']").attr("href");

You can give it a try here, you may also want $(".videoTitle[href*='/" + id + ":']") to narrow it down to /1581889025: matches, in case there was a 15818890250 for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文