Asp.net模态窗口Javascript url传递

时间:2015-08-10 17:43:15

标签: javascript asp.net modal-dialog carousel

我创建了一个脚本,可以创建一个可以通过多种图像滑动的轮播。当我点击某个项目时,会显示一个新的模态窗口。 模态窗口包含链接到YouTube视频的iframe。

问题是我想根据用户在转盘中点击的内容更改为所需YouTube视频的网址。我可以点击点击的ID,但我不知道如何更改iframe。仍然是javascript的初学者。

这是我的代码

                  function handleLeftClick(id){             var a = $(“#testvid”+ id).attr('src');             警报(A);         };

     // When the player is ready, add listeners for finish, and playProgress
    player.addEvent('ready', function () {
        player.addEvent('finish', onFinish);
        player.addEvent('playProgress', onPlayProgress);
    });

    function onFinish(id) {
        $('#myCarousel').carousel('pause');

// $('#myCarousel')。carousel('play');     }

function onPlayProgress(data, id) {
    $('#myCarousel').carousel('pause');
}

// invoke the carousel
$('#myCarousel').carousel({
    interval: 1000,
    pause: "hover"
});

//Modal Window


$(document).ready(function () {

    /* Get iframe src attribute value i.e. YouTube video url

    and store it in a variable */

    var url = $("#myModal").attr('src');



    /* Assign empty url value to the iframe src attribute when

    modal hide, which stop the video playing */

    $("#myModal").on('hide.bs.modal', function () {


        $("#youtubeVideo").attr('src', '');

    });



    /* Assign the initially stored url back to the iframe src

    attribute when modal is displayed again */

    $("#myModal").on('show.bs.modal', function () {

        $("#cartoonVideo").attr('src', url);

    });

});

$('。activate_modal')。click(function(){

          //get the id of the modal window stored in the name of the activating element  
          // var modal_id = $(this).attr('name');  


          //use the function to show it  
          //show_modal(modal_id);  
        alert("Hello! I am an alert box!!");
    }); 

</script>

                                                 

                                                           ×                     YouTube视频                                                                                               

1 个答案:

答案 0 :(得分:0)

要解决此问题,请在handleleftClick中添加此内容

$(".modal-body").html('<iframe id="youtubeVideo" width="100%" height="350px" frameborder="0" scrolling="no" src=" ' + a + '?html5=1"; "  allowtransparency="true" allowfullscreen ></iframe>');