将变量获取到url并导航选定的变量

get variable to url and navigate variable selected

本文关键字:变量 导航 url 获取      更新时间:2023-09-26

有人能帮我处理代码吗

我的页面是关于切换iframe 的

当我点击视频1时,它有数据str="p9zdCra9gCE"

它将只更改class="load_video"中iframe的src结尾

所以我需要这样做。。。当我点击视频1或视频2时,我应该在url上获得"p9zdCra9gCE",使其看起来像page.php?p9zdCra9gCE

那么当有人导航到page.php时呢?p9zdCra9gCE还是page.php?0_MfMUN_FNM那么数据str应该在iframe上,而不是通过点击视频按钮来切换。希望你们能理解,伙计们,到目前为止没有人帮过我。

这是我在plnkr上的完整代码http://plnkr.co/edit/IPY3GF7Poyv1URrk84FH?p=preview

这是我的php代码

<?php
        $id = 1;
        foreach (glob('directory/*.php') as $file) {
            $file = str_replace('directory/', '', $file);
            $file = str_replace('.php', '', $file); ?>
            <div style="display:block;" class="video_link" data-str="<?php echo $file; ?>">Video <?php echo $id++ ?></div>
        <?php }
        ?>

这是我的javascript代码

<script>
    $(document).ready(function() {
        $(".frame_src").attr("data-src", "https://www.youtube.com/embed/p9zdCra9gCE");
        var t = "p9zdCra9gCE",
            e = $(".embed_code").attr("data-content");
        e = e.replace("[videoID]", t), $(".embed_code").html(e), $(".video_button").slideDown(), $(".video_link").click(function() {
            $(".reloadframe").show();
            var t = $(this).attr("data-str"),
                e = "https://www.youtube.com/embed/" + t + "",
                a = $(".embed_code").attr("data-content");
            a = a.replace("[videoID]", t), $(".embed_code").html(a), $(".frame_src").attr("src", e), clearInterval(interval), document.querySelector(".load_video").style.display = "none", $(".frame_src").show()
        })
    });
            </script>

查看jQuery的.click().on()方法文档。您希望使用阻止默认点击操作(在这种情况下,您将停止链接导航到新页面),并将其替换为使用所述链接更新iframe。代码看起来像这样:

$(document).ready(function() {
    //bind listener to elements the are used to update the iframe
    $('.updateFrame').on('click', function(e) {
        e.preventDefault(); //stop normal click event
        $('.videoFrame').attr('src', $(this).data('src')); //update iframe src
    });
});