在我的函數中,雖然我將click事件添加到對象,即調用兩次。我發現沒有。解決方案的形式,但沒有任何幫助。jquery單擊事件調用2次
任何人都可以幫我解決這個問題嗎?
我的代碼:
function accordionOptions(AccordionBox, AccordionSec) {
var accordionBox = AccordionBox,
accordionSec = AccordionSec;
$.each(accordionSec, function (i, values) {
$('h3', values).each(function() {
$(this).unbind('click').bind('click', function() {
$(this).toggleClass('selected').siblings('.expand-area').slideToggle().end().parent().siblings().children('h3').removeClass('selected').siblings('.expand-area').slideUp();
var subSec = $(this).parent().children().find('.subSec');
$(subSec).click(function() {
console.log(this.tagName); // i am getting 2 times...why?
})
});
})
})
}
$(document).ready(function() {
var accordionBox = $('#Accordion'),
accordionSec = {
accorIndice: $('#sec1', '#Accordion'),
accorGeography: $('#sec2', '#Accordion'),
accorAllIndia: $('#sec3', '#Accordion')
}
accordionOptions(accordionBox, accordionSec);
});
這是很長的HTML,所以我unabale在這裏放置。對不起
HTML的某些部分:
<ul class='subSec'>
<li>
<h4>1. Select a key index</h4>
</li>
<li>
<label>
<input type="radio" value="CCI" name="cci" checked>Consumer Confidence Index</label>
</li>
<li>
<label>
<input type="radio" value="HW" name="cci">Housewives Index</label>
</li>
</ul>
<ul class='subSec'>
<li>
<h4>2. Select your sub-indices (optional)</h4>
</li>
<li>
<label>
<input type="radio" value="CSI" name="subIndices">Consumer Spending Index</label>
</li>
<li>
<label>
<input type="radio" value="EI" name="subIndices">Employment Index</label>
</li>
<li>
<label>
<input type="radio" value="Ii" name="subIndices">Inflation Index</label>
</li>
<li>
<label>
<input type="radio" value="OI" name="subIndices">Onion Index</label>
</li>
<li>
<label>
<input type="radio" value="CI" name="subIndices">Corruption Index</label>
</li>
</ul>
確定應如何$。每()運行 – Chibuzo 2012-04-02 08:56:42
讓我們看看你的HTML – musefan 2012-04-02 08:57:08
@ 3gwebtrain正常的,因爲你加'class'的點擊裏面''的你h3'so必須點擊兩次,顯示click''log' – mgraph 2012-04-02 09:01:30