Return False 来自点击

Return False From Clicking

我正在尝试点击 如果网站上有一个词 (Hello),请不要做这项工作 但是如果没有一个词 Hello 然后会继续点击 iD(safe)

if ((document.body.innerText).indexOf('Hello') == 1)

{
    return false;


    $('#safe').trigger('click');


}

<html>
  <p>Hello</p> <!-- remove this line to see what if no Hello on page -->

  <button type='button' id='safe' onclick="isHelloThere()">click me</button>

  <script type='text/javascript'>
    function isHelloThere() {
      if ((document.body.innerText).indexOf('Hello') > -1) {
        // do nothing
      } else {
        alert('I do not see a Hello word on the page.')
      }
    }
  </script>
</html>

您可能需要使用更多详细信息来更新您的问题。无论如何,根据您的评论,我想这就是您所需要的。

您可以创建一个点击函数,然后在您的点击函数中判断页面上是否有Hello。 https://jsfiddle.net/jialinzou/cztmusLr/28/