【问题标题】:jQuery to find URI in codeigniterjQuery 在 codeigniter 中查找 URI
【发布时间】:2011-04-15 02:48:31
【问题描述】:

我有一个在我的 codeigniter 网站的每个页面上运行的脚本。

jQuery(document).ready(function($) {
    Cufon.replace('h1');
    $('#term').hint();

    setTimeout('changeImage()',9000);
});

我只想要最后一行 setTimeout('changeImage()',9000); 如果我在基本 url 上并且 URI 中没有段(只希望它在我的主页上运行)。

这是否可以使用 jQuery 执行某种类型的 if 语句并找出 URI 中是否没有段?

谢谢

【问题讨论】:

    标签: javascript jquery codeigniter codeigniter-url


    【解决方案1】:

    你可以通过简单的 javascript 使用 window.location 来做到这一点,你需要担心三件事:路径名、搜索和哈希,代码将类似于:

    var win_location = window.location;
    if ( win_location.pathname === "" || win_location.pathname === "/" && win_location.hash === "" && win_location.search === "")
    {
       // I'M HOME NOW DO SOMETHING
    } 
    // hash will be for things like #anchor in the url
    // search will be for things like ?param1=john&param2=doe
    // so if you need those for some kind of dynamic handling on the home page remove the
    // matching condition
    

    【讨论】:

      【解决方案2】:

      使用window.location

      if ( window.location == YOUR_BASE_URL ) {
          setTimeout('changeImage()',9000);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-24
        • 1970-01-01
        • 2016-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-05
        • 1970-01-01
        相关资源
        最近更新 更多