I'我正在尝试使用javascript中的变量为按钮分配标签

I'm trying to assign a label to a button using a variable in javascript

本文关键字:javascript 变量 标签 分配 按钮      更新时间:2023-09-26

我正在阅读一个播放列表,试图捕捉播放列表中每个项目的标题信息,并将标题分配给由按钮组成的网格中的一个按钮。目标是创建一个类似电子节目指南的东西,用户可以点击它,并让按钮更改主播放窗口中播放的内容。我在下面包含了我当前的代码。非常感谢您的帮助。

谢谢。

<div align="Center" id="playerContainer">
 <div id="nowplaying"></div>
<script type="text/javascript">
jwplayer("nowplaying").setup({
 playlist: "http://content.jwplatform.com/feeds/MFPT0wUf.rss",
 image: "http://content.jwplatform.com/thumbs/Wf8BfcSt-640.jpg",
 width: "580",
 height: "370",
 primary: "html5",
 advertising: { 
  client: "vast",
  tag: "http://demo.tremorvideo.com/proddev/vast/vast2RegularLinear.xml"
  }
});
</script>
<script type="text/javascript">
    var items = jwplayer().ge
tPlaylist(),
      allButtons = ''; //empty str
    for(var i = 0; i < items.length; i++) {
      console.log(items.title);
    var singleButton = '<div class="buttons01"><button type="button">' + items[i].title + '</button></div>';
    allButtons += singleButton; 
    console.log(singleButton);
    // console.log(allButtons);
}
   </script>

</div>
<p></p>

我希望能够通过将上面播放列表中的"标题"值插入下面的"标题#转到这里"空间来自动更改下面每个按钮的标签。

<div class="buttons">
<div class="buttons01">
<button id="Video01" align="center">Title 1 Goes Here</button>
<button id="Video02" align="center">Title 2 Goes Here</button>
<button id="Video03" align="center">Title 3 Goes Here</button>
<button id="Video04" align="center">Title 4 Goes Here</button>
<button id="Video05" align="center">Title 5 Goes Here</button>
<button id="Video06" align="center">Title 6 Goes Here</button>
</div>
<div class="buttons02">
<button id="Video01" align="center">Title 7 Goes Here</button>
<button id="Video02" align="center">Title 8 Goes Here</button>
<button id="Video03" align="center">Title 9 Goes Here</button>
<button id="Video04" align="center">Title 10 Goes Here</button>
<button id="Video05" align="center">Title 11 Goes Here</button>
<button id="Video06" align="center">Title 12 Goes Here</button>
</div>
</div>

不确定你在做什么,你的代码有点乱,但可能。。。

var items = jwplayer().getPlaylist();
for(var i = 0; i < items.length; i++) {
    document.getElementById("buttons0"+i).innerHTML = items[i].title;
}