在页面的 HTML 源代码中,我们有:
<li class="wv-topbar__nav__item">
<a href="/go/business_savings/933dd921-b3d4-be4d-bb0d-e45fe696643d/" class="wv-topbar__nav__link">
Save Money
</a>
</li>
我希望能够从 href 值中获取此字符串:
933dd921-b3d4-be4d-bb0d-e45fe696643d
基本上,第三个和第四个斜杠之间的字符串并将其存储到变量中。
最佳答案
只有一个内衬:
alert($('.wv-topbar__nav__item a') // select anchor element inside the element with class = wv-topbar__nav__item
.attr('href').split('/')[3]);
关于javascript - jQuery 获取 href 值特定部分的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34424764/