从模式中的span的id加载点击的跨度URL

时间:2014-01-13 21:51:22

标签: javascript jquery html css twitter-bootstrap

请注意以下JS小提琴,其中我试图在Video URL模态的iframe中加载Twitter Bootstrap's以及模态标题栏中title attr的标题。请告诉我如何才能使其发挥作用?

http://jsfiddle.net/52VtD/1745/

<span id="http://player.vimeo.com/video/78360422" title="Introduction to this video" class="btn btn-warning" ><a data-toggle="modal" data-target="#myModal" href="http://player.vimeo.com/video/78360422" target="ifr">1) VIDEO TO LOAD IN IFRAME # 1</a> </span><br><BR>
<span id="http://player.vimeo.com/video/53671222" title="About It" class="btn btn-warning" > 2) VIDEO TO LOAD IN IFRAME # 2 </span>

<!-- Button trigger modal --><br><BR>
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Span Title Attr Text Here</h4>
      </div>
      <div class="modal-body">
                                                                 <iframe name="ifr" src='' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> 

      </div>
          </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

3 个答案:

答案 0 :(得分:1)

$(document).on("click", "span.btn", function () {
     var title = $(this).prop('title'),
         id = $(this).prop('id'); 
     $(".modal-title").text(title);
     $(".modal-body").html($("<iframe src=" + id + "></iframe>"));
});

示例:http://jsfiddle.net/52VtD/1766/

答案 1 :(得分:0)

  1. 清理html代码可能吗?这很难读:(
  2. 你的第二个标签目标应该设置为'#ifr',就像其他两个链接(按钮)的工作方式一样
  3. 将您的iframe src设置为您的视频链接,例如: ,不要把它放在你的跨度id

答案 2 :(得分:0)

您可以使用以下命令在bootstrap模式中打开外部链接:

<a data-target="#externalModal" href="externalmodal" role="button" data-toggle="modal">External url</a>