0
4

3 回答 3

0
于 2013-04-03T07:19:39.047 回答
0

这将为所有 A 标签添加一个禁用的类,其中它们的 href 与具有所选类的任何元素的 id 匹配:

$(function() {
    $("a").removeClass('disabled');
    $('.selected').each(function() {
        $('a[href=#' + $(this).attr('id') + ']').addClass('disabled');
    });

// If by 'disabled', you mean you want the link not to work, then add this:

    $('a.disabled').on('click',function(e) {
        alert('you can\'t do that');
        e.preventDefault();
        return false;
    });
});

这里的例子:http : //jsfiddle.net/dtxan/4/

于 2013-04-03T07:23:38.050 回答
0

像这样的东西应该工作。

$(".selected").each(function() {
    $('a[href="#' + $(this).attr("id") + '"]').click(function(e) {
        e.preventDefault();
    })
})
于 2013-04-03T07:24:17.373 回答