我试图模拟在我的html页面上点击链接的过程。我正在使用jquery
.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");
});
这是鞋带
纳芙丸
HTML:
<!-- 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 -->
我找到了一些没有给我所需结果的帖子:
How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?
jquery click() on a link
Having trouble using jquery to click on a link
click event on a link doesn't work in jquery