我按下鼠标按钮但在释放鼠标按钮之前尝试激活链接。
示例代码http://codepen.io/MHUMPHRI/pen/GqJGre?editors=1010re?editors=1010
在我的示例代码中,当选择LHS链接并释放鼠标按钮时,将显示RHS选项卡中的内容。我希望在按下鼠标按钮后立即显示标签内容。感谢任何帮助。迈克
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<div class="container-fluid">
<div class="row">
<div class="nopadding col-xs-4">
<a class="active" data-toggle="pill" href="#content1">
<div class="blue-box col-xs-12">
<h1>box1<h1>
</div>
</a>
<a data-toggle="pill" href="#content2">
<div class="blue-box col-xs-12">
<h1>box2<h1>
</div>
</a>
<a data-toggle="pill" href="#content3">
<div class="blue-box col-xs-12">
<h1>box3<h1>
</div>
</a>
</div>
<div class="nopadding col-xs-8">
<div class="tab-content">
<div id="content1" class="tab-pane fade in active">
<div class="col-xs-12 grey-box">
<h1>output1<h1>
</div>
</div>
<div id="content2" class="tab-pane fade">
<div class="col-xs-12 grey-box">
<h1>output2<h1>
</div>
</div>
<div id="content3" class="tab-pane fade">
<div class="col-xs-12 grey-box">
<h1>output3<h1>
</div>
</div>
</div>
</div>
答案 0 :(得分:3)
因为你导入了jQuery,这里是一个jQuery解决方案:
首先,用$(document).ready(function() { ... });
然后添加代码:
var pills = $('a[data-toggle="pill"]');
pills.mousedown(function() {
this.click();
});
这样,无论何时点击并按住(.mousedown
),您都会在同一元素上调用整个.click
事件。