我有一個問題,當我點擊鏈接p打開,然後點擊另一個鏈接它不起作用。它在我再次點擊時起作用。JQuery切換()函數
這是我的jQuery代碼:
var toggle = 0;
$(document).ready(function() {
$(".feedback_block").each(function() {
$("a", this).click(function (e) {
if (toggle == 0) {
$(this).parent().children("p").stop(true, true).fadeIn(500);
$(this).addClass("clicked");
$(this).children().addClass("clicked_span");
toggle = 1;
console.log(toggle);
} else
if (toggle == 1) {
$(this).parent().children("p").stop(true, true).fadeOut(500);
$(this).removeClass("clicked");
$(this).children().removeClass("clicked_span");
toggle = 0;
console.log(toggle);
}
e.stopPropagation();
return false;
});
toggle = 0;
});
});
當我點擊參數切換獲得1
,當我點擊另一個鏈接的初始值應爲0。我該怎麼辦呢?
我的例子:http://jsfiddle.net/amkrtchyan/tjzaR/
我編輯過這個,但是S/O編輯器拒絕了大約10個建議的標題(真氣)。任何人,請改進我的(即將發佈的)編輯。 – halfer 2012-03-20 10:38:29