简体   繁体   English

使用ID选择一个具有ID的div并在页面加载时自动单击它

[英]Selecting a div with an ID and automatically clicking on it on page load with JQuery

I have a div on my page with the ID of #activateeditbutton . 我的页面上有一个div,ID为#activateeditbutton I want this div to be automatically clicked when the page loads. 我希望此div在页面加载时自动单击。

Here is the code I have written in jQuery, but it does not seem to work. 这是我用jQuery写的代码,但似乎不起作用。 If someone can point out my mistake I would greatly appreciate it. 如果有人指出我的错误,我将不胜感激。 Thanks. 谢谢。

<script type="text/javascript">

jQuery(document).ready(function(){
  $('#activateeditbutton').simulate('click');
});

</script>

Try this, 尝试这个,

jQuery(document).ready(function(){
      $('#activateeditbutton').trigger('click');
    });

您需要使用.trigger()

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

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

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