我有这样的html结构
<div class="selected">
<div class="selectedOption">September 2012</div>
</div>
<div class="optionsContainer" style="width: 138px;">
<div class="option">July 2012</div>
<div class="option">August 2012</div>
<div class="option">September 2012</div>
<div class="option">October 2012</div>
<div class="option">November 2012</div>
</div>
我试图将“selected”类应用于内容等于“selectedOption”div的选项
jQuery('.optionsContainer .option').click(function(){
// call an one ajax too
jQuery.each(jQuery('.optionsContainer .option'),function(index,value){
var temp = jQuery(this).html();
var selected_date = jQuery(".selectedOption").html();
if(temp == selected_date)
{ alert('in');
jQuery(this).addClass('selected');
}
});
});
它工作正常,但问题是如果我删除警报意味着未应用“选定”类。有任何想法吗?提前致谢