asp.net mvc一个href id

时间:2010-09-09 09:59:21

标签: jquery asp.net-mvc

  $('a').click(function () {
             var href = this.href;
             //alert('I was clicked, here my href = ' + $(this).attr('href'));
             var divid = $(this).attr('href');
             $("#" + divid).slideToggle('slow'); // show hide div
             $("#" + divid + "1").slideToggle('slow'); // show hide div
             $("#" + divid + "2").empty();
             $("#" + divid + "4").empty();
             return false;
         });

如何唯一地识别一个href? 。在href中包含一个id并调用?

2 个答案:

答案 0 :(得分:0)

ID在页面中始终是唯一的,或者至少应该是。所以给你的锚一个ID,它应该是固定的。一个锚也可以只有1个href。所以我不确定你想要什么。

答案 1 :(得分:0)

$('a').click(function () {
    // Get the id of the link:
    var id = this.id;
    $("#" + id + "1").slideToggle('slow'); // show hide div
    $("#" + id + "2").empty();
    $("#" + id + "4").empty();
    return false;
});