我想在一些使手風琴展開和摺疊的鏈接文本旁邊添加一個圖標。文本已經從'See more'改變爲'See less'。看到工作演示 - http://bootply.com/106271jquery裏面的HTML標記
因此增加:
<span class="glyphicon glyphicon-chevron-up"></span>
停止文本變化工作。
這裏是破碎的版本嘗試添加該圖標:http://bootply.com/106270
$(document).ready(function(){
$("#morebtn").click(function(){
$(this).html($(this).html() == "See more <span class="glyphicon glyphicon-chevron-up"></span>" ? "See less" : "See more <span class="glyphicon glyphicon-chevron-up"></span>");
});
});
'$(this).html('.....')' – Abhitalks
Duplicate http://stackoverflow.com/questions/21159802/link-text-changes-on-click-see-more-see- less-jquery-bootstrap-accordion/21159947#21159947 –
不要替換整個html ...有更好的方法來遍歷DOM。您應該只是替換文本,並更改嵌套範圍的類 – series0ne