내 함수에서 click 이벤트를 객체에 추가하는 동안 두 번 호출합니다. 나는 찾지 못했다. 형태의 해결책은 없었지만 아무런 도움이되지 못했습니다.jquery click 이벤트 호출 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>
$ .each() 실행 방법 결정 – Chibuzo
h3의 'click'내에 'click of class'를 추가했기 때문에 – musefan
@ 3gwebtrain을 정상적으로 볼 수 있습니다. 그러면 'log'를 표시하기 위해 두 번 클릭해야합니다. – mgraph