Javascript jquery.click()完成的过程与实际单击链接的过程不同;需要单击实际链接才能使流程正常工作
我试图模仿在我的HTML页面上点击链接的过程。我正在使用选择器上的jQueryJavascript jquery.click()完成的过程与实际单击链接的过程不同;需要单击实际链接才能使流程正常工作,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我试图模仿在我的HTML页面上点击链接的过程。我正在使用选择器上的jQuery。click()函数。该链接是基于选项卡的引导导航表单的一部分。当我点击nav-pills链接时,效果非常好-表单上的选项卡显示并显示该选项卡上的所有字段。当我运行下面的代码时—.click()函数—它会显示选项卡,但在我手动单击该导航链接之前,选项卡上不会显示任何字段 代码如下: $("#tabDocumentsTab").click(); 下面是我要运行的函数/选择器代码: $("#tabDocumentsTab
。click()
函数。该链接是基于选项卡的引导导航表单的一部分。当我点击nav-pills
链接时,效果非常好-表单上的选项卡显示并显示该选项卡上的所有字段。当我运行下面的代码时—.click()
函数—它会显示选项卡,但在我手动单击该导航链接之前,选项卡上不会显示任何字段
代码如下:
$("#tabDocumentsTab").click();
下面是我要运行的函数/选择器代码:
$("#tabDocumentsTab").click(function (e) {
console.log("tabDocumentsTab START");
// Display Provider files...
displayProviderFileUploads();
// Display Adult PTP files...
displayAdultPTPFileUploads();
// Display Other files...
displayOtherFileUploads();
// Set the Page color To Non-State...
changePageColorToNonState();
// Set the current tab number...
setCurrentPage(1);
var linkText = $(this).text();
var index = $(this).index();
// If State Use Only tab - add text...
if (index > 6 && index < 10) {
linkText = linkText + " (State Use Only)";
}
// Now set the h3 value...
$("#mainTitleH3").text(linkText);
e.preventDefault();
// Show current link section, hide all the rest...
for (x = 0; x < totalSections; x++) {
if (x == index) {
// Show the current section...
$("#displaySection" + x).show();
} else {
// Hide the rest...
$("#displaySection" + x).hide();
}
}
console.log("tabDocumentsTab END");
});
我发现一些帖子没有给我想要的结果:
要在引导中显示选项卡,需要使用$(选择器).tab('show')
。看
$('menu1').tab('show')//显示第二个选项卡(菜单1)
引导示例
可切换标签
-
-
-
家
知识产权是一种权利,是一种精英的权利,是劳动和财富的暂时性权利
菜单1
但是,在最低限度上,我们需要一个实验室来进行日常工作
菜单2
在所有人都有错误的情况下,我们必须清楚地看到,所有的人都有错误
用$('tabDocumentsTab')试试。触发器('click')看看
<!-- This is the NAVGIVATION section -->
<div class="col-sm-2">
<ul class="nav nav-pills nav-stacked" id="mainNavList">
...
<li>
<a id="tabDocumentsTab" data-toggle="pill" href="#displaySection1">Documents</a>
</li>
...
</ul>
</div>
<!-- End of NAVGIVATION section -->
$("#tabDocumentsTab").tab('show');