选择一个li项目,然后启用一个输入按钮

时间:2012-12-11 16:25:08

标签: jquery

我创建了一个列表,当我选择高光时,我只想要一个项目突出显示 - 同样当项目突出显示时我需要启用按钮 - 例如下面:

 $('#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");
        }
    });

http://jsfiddle.net/zidski/rEH5L/

1 个答案:

答案 0 :(得分:3)

替换

$(this).parent('li').toggleClass('highlight');

$(this).parent('li').addClass('highlight').siblings().removeClass('highlight');

其次,我没有看到声明此变量的位置currentPage

这在当前上下文中没有意义,因为这些没有在您提到的代码中定义。

if (!currentPage.parent().hasClass('highlight')) {

<强> Check Fiddle