duang8642 2014-08-28 14:23 采纳率: 0%
浏览 155
已采纳

如何在单击链接时使URL唯一

i have code like this in a page called list.php when i click a link the video in the iframe was change into the video i selected but in the address bar its still list.php how can i make the url be list.php/Anohana10? or something like that?

<script>
    $(document).ready(function(){
    $("ul#videos li a").click(function(e) {
        e.preventDefault();

        $("#video").attr("src", $(this).attr("href"));
    })
});
</script>

<div class="videoWrapper">
    <IFRAME  id="video" SRC="http://upload4free.co/embed-trdcgvsgf0tj-500x300.html" FRAMEBORDER=0  
        webkitAllowFullScreen ></IFRAME>
    </div>

<ul id="videos">
    <li><a id="Anohana10" href="http://upload4free.co/embed-ndi71khpdvbf-580x300.html">Anohana Episode 10</a></li>
    <li><a id="Anohana9" href="http://upload4free.co/embed-flm2y2648udr-580x300.html">Anohana Episode 9</a></li>

  • 写回答

1条回答 默认 最新

  • douzhi1813 2014-08-28 14:37
    关注

    You could, instead of intercepting the <a>'s default behaviour of redirecting the page, let it anchor the information, like <a id="Anohana10" href="#Anohana10">, then your page's url would look like: list.php#Anohana10.

    The iframe's link information, you can store on another custom attribute (let's say data-url), and retrieve it with your jquery function:

    <script>
        $(document).ready(function(){
        $("ul#videos li a").click(function(e) {
            $("#video").attr("src", $(this).attr("data-url"));
        })
    });
    </script>
    
    <div class="videoWrapper">
        <IFRAME  id="video" SRC="http://upload4free.co/embed-trdcgvsgf0tj-500x300.html" FRAMEBORDER=0  
            webkitAllowFullScreen ></IFRAME>
        </div>
    
    <ul id="videos">
        <li><a id="Anohana10" href="#Anohana10" data-url="http://upload4free.co/embed-ndi71khpdvbf-580x300.html">Anohana Episode 10</a></li>
        <li><a id="Anohana9" href="#Anohana9" data-url="http://upload4free.co/embed-flm2y2648udr-580x300.html">Anohana Episode 9</a></li>
    

    EDIT

    To get the anchor from the URL when typing it directly, add this to the ready jquery method:

    $(document).ready(function(){
    
        var identifier = window.location.hash;
        if(identifier != "")
            $(identifier).click();
    
        $("ul#videos li a").click(function(e) {
        ...
    });
    

    This will get the #id from the url, and perform the click of the corresponding <a> tag, loading the video...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)