简体   繁体   English

页面加载后如何在jquery中调用onclick事件

[英]how to call onclick event in jquery once page loads

I am using following code for a particular page on which i want the tabs(course descriptions and other version) to be clicked and show contents during the page load but it is not working...here is the code with the link of the page: 我正在为特定的页面使用以下代码,我希望在该页面上单击选项卡(课程说明和其他版本)并在页面加载期间显示内容,但是它不起作用...这是带有页面链接的代码:

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/ https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/

window.onload=function() {
  init();
  function init() {
    var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
    var id = getHash( tabLink.getAttribute('href') );
    tabLinks[id] = tabLink;
    contentDivs[id] = document.getElementById( id );
    var i = 0;
    for ( var id in tabLinks ) {
      tabLinks[id].onclick = showTab;
      tabLinks[id].onfocus = function() { this.blur() };
      if ( i == 0 ) tabLinks[id].className = 'selected';
      i++;
    }
  }
}

But i am little bit confused in syntax part. 但是我在语法部分有点困惑。 the tabs are only able to show contents when the entire page loads. 这些选项卡仅在整个页面加载时才能显示内容。 but i need to show the content when user clicks on tabs during please loading. 但是当用户在加载过程中单击选项卡时,我需要显示内容。

Hi You can do this as given below 您好,您可以按照以下步骤进行操作

$("document").ready(function() {
setTimeout(function() {
var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
var id = getHash( tabLink.getAttribute('href') );

  $("id").trigger('click');
},10);
});

Hope it helps you 希望对您有帮助

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

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