javascript - 从嵌入脚本中获取 Javascript 中的 ID 作为变量

标签 javascript jquery jwplayer

我正在尝试获取嵌入脚本的视频 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/

相关文章:

javascript - 将 JWplayer 嵌入代码从数据库集合加载到meteor.js 中的页面模板中

javascript - JWPlayer : issue in stop and play using javascript

javascript - 如何将按键上的事件监听器添加到 Chrome 的地址栏 - Chrome 扩展

javascript - 更改文本后的 jQuery 高度段落就绪事件

jquery - 使用表单值通过 jquery 更改 CSS

jwplayer - JW 播放器 : What edition do I need to show ads?

javascript - 选择数据特定 ID 并在其他数据处添加值

javascript - 如何查看给定 JS 对象的所有属性?

javascript - 带有 templateResult 和 templateSelection 的 jquery select2 (4.0) ajax

javascript - 修改函数参数