【问题标题】:If text exists, reload the page如果文本存在,则重新加载页面
【发布时间】:2013-02-08 18:15:36
【问题描述】:

我正在尝试在页面上搜索文本,如果找到文本,请重新加载页面。

<p class="textmedium">These are the droids I'm looking for</p>

【问题讨论】:

  • 那么&lt;p&gt; 正是您要找的?
  • @Sugitime 如果您的页面内容在每次页面重新加载时都没有改变,重新加载将导致无限重新加载循环。也许不是重新加载,而是重定向到不同的 URL?

标签: javascript jquery


【解决方案1】:

应该这样做:

if($('*:contains("These are the droids I\'m looking for")').length > 0) {
    document.href.location = document.href.location; // refresh the page
}

【讨论】:

【解决方案2】:

我会说:

$("p.textmedium").each(function() {
    if ($(this).html == "These are the droids I'm looking for") window.location.reload();
});

【讨论】:

    【解决方案3】:

    用户 jquery 的 javascript:

    <p class="textmedium" id="ptag" >These are the droids I'm looking for</p>
    
    <script type="text/javascript" >
    
    var text = $("#ptag").html();
    
    var isFound = text.search(/word-you-are-searching-for/i);
    if(isFound){
        document.href="page you redirect to";
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-02
      • 2021-09-24
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 2021-12-06
      • 2011-06-29
      • 1970-01-01
      相关资源
      最近更新 更多