我正在尝试获取嵌入脚本的视频 ID。每次视频的 ID 都会发生变化,因此我需要以某种方式获取它。
这是添加到 HTML 文档中的嵌入行:
<script src="https://content.jwplatform.com/players/80HZjDPO-V5C9t34F.js"></script>
这就是它生成的内容:
<div id="botr_80HZjDPO_V5C9t34F_div" class="jwplayer jw-reset jw-state-paused jw-stretch-uniform jw-flag-aspect-mode jw-breakpoint-4 jw-flag-user-inactive" tabindex="0" aria-label="Video Player" role="application" style="width: 100%;">
这是我要抓取的id:
id="botr_80HZjDPO_V5C9t34F_div"
我注意到这总是一样的:
botr_ ****** _V5C9t34F_div
我如何才能获取这个 ID 并在我的 Javascript 中使用它?
最佳答案
您可以在属性选择器中使用 $
来匹配字符串 $("div[id$='_V5C9t34F_div']")
的结尾。
[name$=”value”]
Description: Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.
关于javascript - 从嵌入脚本中获取 Javascript 中的 ID 作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52312236/