最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to trigger click event of button after period of time in javascript - Stack Overflow

programmeradmin4浏览0评论

I tried to trigger click event of button after 3 mins using below javascript code

setTimeout(function(){$(‘._my_save_button’).trigger(‘click’)},180000);

Above code throws error when we run in chrome console

Uncaught SyntaxError: Invalid or unexpected token

I tried to trigger click event of button after 3 mins using below javascript code

setTimeout(function(){$(‘._my_save_button’).trigger(‘click’)},180000);

Above code throws error when we run in chrome console

Uncaught SyntaxError: Invalid or unexpected token
Share edited Mar 13, 2019 at 16:02 rocky asked Mar 13, 2019 at 15:57 rockyrocky 8312 gold badges11 silver badges31 bronze badges 4
  • 2 setTimeout(function(){$('_my_save_button').trigger('click')},180000); .............. ‘_my_save_button’ => '_my_save_button' – Pranav C Balan Commented Mar 13, 2019 at 15:59
  • 2 Your single quotes are 'weird'. Try using normal single (or double) quotes: ' or ". Also, your _my_save_button is really nothing. If it's the id of the button, you should add the prefix # to that. – ZiNNED Commented Mar 13, 2019 at 15:59
  • does your button have the class or id _my_save_button? if it is the class, prepend it with a ., if id, prepend with #. – Matthew Varga Commented Mar 13, 2019 at 16:00
  • Looks like dublicate of stackoverflow./q/7188145/8623919 – Bijay Yadav Commented Mar 13, 2019 at 16:06
Add a ment  | 

2 Answers 2

Reset to default 6

We need to fix the quotes around your identifier.

setTimeout(function() {
    $('._my_save_button').trigger('click');
}, 3000);

I think you are only missing the right css selector.

should be "#_my_save_button" in case of id="_my_save_button" or "._my_save_button" in case of class="_my_save_button":

setTimeout(function(){$("#_my_save_button").trigger("click")},180000);
发布评论

评论列表(0)

  1. 暂无评论