問題描述:bootstrap nav-tabs怎么選中當前項active屬性
為什么使用js或者jquery 如下設(shè)置class和移除class active屬性后,還是無反應(yīng)笤妙?或者點一下就變回去了冒掌?
<li role="presentation" class="roleText active" id="roleText">
<a here ="http://www.it399.com/" onclick="changeToText();" >文本</a></li>
<li role="presentation" class="roleNetUrl" id="roleNetUrl">
<a here ="http://www.it399.com/" onclick="changeToNetUrl();" >網(wǎng)址</a></li>
<!-- <li role="presentation" class="">
<a >在線助手-你的在線工具箱</a></li>-->
<script type="text/javascript">
function changeToText(){
//移除選中
$('#roleNetUrl').removeClass("active");
$('#roleText').removeClass("active");
//設(shè)置選中
$('#roleText').addClass("active");
}
</script>
<script type="text/javascript">
function changeToNetUrl(){
//移除選中
$("#roleText").removeClass("active");
$('#roleText').removeClass('active');
$('#roleNetUrl').addClass('active');
//設(shè)置選中
}
</script>
后面發(fā)現(xiàn)是a標簽的herf屬性定位到了 在線助手 首頁:http://www.it399.com
這樣點擊的時候就會刷新頁面,所以設(shè)置的效果就看起來一閃而過蹲盘,又恢復(fù)到了之前的狀態(tài)股毫。
如果點擊標簽頁不需要跳轉(zhuǎn)頁面,那么去掉herf即可召衔。其它首頁導(dǎo)航以此類推铃诬。點此可以查看效果:藝術(shù)彩色二維碼在線生成-在線助手,你的在線工具箱!