简体   繁体   English

在点击 Javascript 之前执行按钮方法

[英]Execute Button Method before clicking in Javascript

document.write(
  '<button class="list" href="#X1" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"> Home </button>'+
  '<div class="collapse list-unstyled" id="X1">'+
     '<a href="'+myArray[0][0]+'" class="'+myArray[0][1]+'" > Site 1 </a> '+
     '<a href="'+myArray[1][0]+'" class="'+myArray[1][1]+'" > Site 2 </a> '+
  '</div>'
);

I have a Navigation Menu with submenus full of links.我有一个导航菜单,其中包含充满链接的子菜单。 Whichever page the user is currently in, i want the particular submenu to be expanded (By Default it will be compressed)无论用户当前在哪个页面,我都希望扩展特定的子菜单(默认情况下它将被压缩)

In the above code, when the user clicks on a menu item, the submenus will open up.在上面的代码中,当用户点击一个菜单项时,子菜单就会打开。 Is there anyway i can open up this submenu without user clicking on it.无论如何我可以打开这个子菜单而不需要用户点击它。 Using BOOTSRAP SideNav for Navigation, so a bit confused使用 BOOTSRAP SideNav 进行导航,所以有点困惑

Setting aria-expanded="false" to aria-expanded="true" does not workaria-expanded="false"设置为aria-expanded="true"不起作用

You can add class show to the div.collapse that you want to expand.您可以将 class show添加到要展开的div.collapse中。

Example:例子:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample"> Menu </a> <div class="collapse show" id="collapseExample"> <div class="card card-body"> Submenu </div> </div>

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

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