Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果存在文本,请重新加载页面_Javascript_Jquery - Fatal编程技术网

Javascript 如果存在文本,请重新加载页面

Javascript 如果存在文本,请重新加载页面,javascript,jquery,Javascript,Jquery,我试图在页面上搜索文本,如果找到文本,请重新加载页面 <p class="textmedium">These are the droids I'm looking for</p> 这些就是我要找的机器人 这应该做到: if($('*:contains("These are the droids I\'m looking for")').length > 0) { document.href.location = document.href.location

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

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

这些就是我要找的机器人

这应该做到:

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

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

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

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

用户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>

这些就是我要找的机器人

var text=$(“#ptag”).html(); var isFound=text.search(/word您正在搜索的/i); 如果(isFound){ document.href=“您重定向到的页面”; }
用户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>

这些就是我要找的机器人

var text=$(“#ptag”).html(); var isFound=text.search(/word您正在搜索的/i); 如果(isFound){ document.href=“您重定向到的页面”; }
,因此您要寻找的是准确的
。@Sugitime如果您的页面内容在每次重新加载时都没有改变,重新加载将导致无限的重新加载循环。可能不会重新加载,但重定向到不同的URL?因此,确切的
就是您要查找的内容?@Sugitime如果您的页面内容在每次重新加载时都没有改变,重新加载将导致无限的重新加载循环。可能不重新加载,但重定向到其他URL?位置。重新加载();可能需要刷新吗?JS中有一个,但上面是第一个想到的。location.reload();也许要刷新一下?JS中有一个错误,但上面是第一个想到的。