繁体   English   中英

使用setinterval时$找不到错误

[英]$ not found error while using setinterval

我试图在创建按钮时自动单击它,并在单击按钮后关闭间隔。 但是下面的脚本给了我$ is not defined错误。 谁能帮助我我在哪里做错了?

var timer = setInterval(
    function () { 
        if ($('#element')) { 
            $('#element').click(); 
            clearInterval(timer);
        } 
        else 
        { 
            console.log('Element not found'); 
        }
    }, 1000);

仅当您使用jQuery时,将其cdn添加到您的html页面中

<script
  src="https://code.jquery.com/jquery-2.2.4.js"
  integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
  crossorigin="anonymous"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM