我正在尝试在页面加载时加载#panelInfo
列表项。我错过了什么?
HTML:
<ul class="dropdown-menu">
<li>
<a class="hidden-md hidden-lg" href="#2dTab" aria-controls="2Dtab" role="tab" data-toggle="tab"> Map</a>
</li>
<li>
<a class="active hidden-md hidden-lg" href="#3dTab" aria-controls="3Dtab" role="tab" data-toggle="tab"> Scene</a>
</li>
<li>
<a role="button" data-target="#panelInfo" aria-haspopup="true">
<span class="glyphicon glyphicon-info-sign"></span>
Info
</a>
</li>
JS:
$(document).ready(function() {
$('#dropdown-menu li:nth-child(3)').click();
console.log('CLICKED');
});
答案 0 :(得分:0)
你在LI元素上调用click(),试试这个。
$(document).ready(function() {
$('#dropdown-menu li:nth-child(3) a')[0].trigger('click');
console.log('CLICKED');
});
答案 1 :(得分:0)
您可以使用data-target属性触发点击。
$('.dropdown-menu a[data-target="#panelInfo"]').trigger('click');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="dropdown-menu">
<li>
<a class="hidden-md hidden-lg" href="#2dTab" aria-controls="2Dtab" role="tab" data-toggle="tab"> Map</a>
</li>
<li>
<a class="active hidden-md hidden-lg" href="#3dTab" aria-controls="3Dtab" role="tab" data-toggle="tab"> Scene</a>
</li>
<li>
<a role="button" data-target="#panelInfo" aria-haspopup="true">
<span class="glyphicon glyphicon-info-sign"></span> Info
</a>
</li>
</ul>
&#13;