如何在src中获取html id输出

How to get html id output in src

本文关键字:html id 输出 获取 src      更新时间:2024-04-29

试图在视频源src和海报中获得html id输出

<video id="really-cool-video" class="video-js vjs-default-skin" controls
 preload="auto" width="640" height="264" poster="$('#posterURL').html();"
 data-setup='{}'>
  <source src="$('#videoURL').html();" type='video/mp4'>
</video>
<div id="posterURL"></div>
<div id="videoURL"></div>

您可以使用jQuery的.attr()函数来实现这一点:

$(document).ready(function(){
    var posterUrl = $('#posterURL').html();
    var videoUrl = $('#videoURL').html();
    $('#really-cool-video').attr('poster', posterUrl);
    $('source').attr('src', videoUrl);
)};