我有這個簡單的Fiddle,如果用戶點擊plus
圖形,我會顯示摺疊的內容,並在點擊minus
glyphicon時將圖標更改爲「減號」,反之亦然。如何防止雙擊「點擊」jquery
但是,當我雙擊plus
圖形時,內容顯示並且圖形不會更改爲minus
。對於接下來的單擊,當「減號」圖形出現時顯示內容。我怎樣才能防止雙擊?
HTML
<div class="divcontainer">
<span>Click -----></span>
<span class="glyphicon glyphicon-plus" data-toggle="collapse" href="#collapsecontent"></span>
</div>
<div class="collapse" id="collapsecontent">
content
</div>
jQuery的
$(document).ready(function() {
$('.glyphicon-plus').click(function() {
$(this).parent("div").find(".glyphicon-plus")
.toggleClass("glyphicon-minus");
});
});
是的,它是。你是如何嘗試從這個問題的解決方案? $(document).ready(function(){(「。glyphicon-plus」)。one('click',function(event){ event.preventDefault(); // do something $(this) (「div」)。find(「。glyphicon-plus」) .toggleClass(「glyphicon-minus」); }); }); – CristiC
@CristiC,我試過了,但不適合這種情況。 - 按鈕不會變回+按鈕 –
@CristiC正確檢查您的小提琴,它不會更改下次點擊的圖標。另外,刪除重複,以便我會得到答案。 – Raviteja