我创建了一个列表,当我选择高光时,我只想要一个项目突出显示 - 同样当项目突出显示时我需要启用按钮 - 例如下面:
$('#sn-list li a').click(function () {
$(this).parent('li').toggleClass('highlight');
if (!currentPage.parent().hasClass('highlight')) {
$('#tabulation_button').removeProp("disabled");
alert('hello');
}
else {
$('#tabulation_button').prop("disabled", "disabled");
}
});
答案 0 :(得分:3)
替换
$(this).parent('li').toggleClass('highlight');
带
$(this).parent('li').addClass('highlight').siblings().removeClass('highlight');
其次,我没有看到声明此变量的位置currentPage
这在当前上下文中没有意义,因为这些没有在您提到的代码中定义。
if (!currentPage.parent().hasClass('highlight')) {
<强> Check Fiddle 强>