2016-03-23 14 views
1

私は異なるIDを持つ4つのリンクを持っていますが、どのリンクをクリックするとjqueryに別のIDを割り当てるのですか?どんな指導も高く評価します。ありがとう!jqueryに動的IDを割り当てます

HTML:

<ul class="dropdown-menu"> 
     <li>@Html.ActionLink("Manage Site", "Index", "Site", null, new { @id = "btn0" })</li> 
     <li>@Html.ActionLink("Manage Segment","Index","Segment", null, new { @id = "btn1" })</li>        
     <li>@Html.ActionLink("Manage Module & URL", "Index", "Modules", null, new { @id = "btn2" })</li> 
     <li>@Html.ActionLink("Manage User Role", "Index", "UserRoles", null, new { @id = "btn3" })</li> 
</ul> 

のjQuery:

$(function() { 
      $(*assign id here*).click(function() { 
       $("#loading").fadeIn(); 
       var opts = { 
        lines: 10, // The number of lines to draw 
        length: 5, // The length of each line 
        width: 4, // The line thickness 
        radius: 10, // The radius of the inner circle 
        color: '#000', // #rgb or #rrggbb 
        speed: 1, // Rounds per second 
        trail: 60, // Afterglow percentage 
        shadow: false, // Whether to render a shadow 
        hwaccel: false // Whether to use hardware acceleration 
       }; 
       var target = document.getElementById('loading'); 
       var spinner = new Spinner(opts).spin(target); 
      }); 
     }); 
+0

あなたは、動的idで何を意味していますか?あなたは割り当てによって何を意味しますか? – madalinivascu

答えて

1

変更$(*assign id here*)$('a[id^="btn"]')または$('.dropdown-menu li a')

+0

はい笑それを聞く必要はありません – madalinivascu

+1

あなたの助けてくれてありがとう! –

0

にあなたは動的に次のようにIDを確認することができます。 各FUNC forループまたは$でそれを入れて追加し、次の

例えば::

for(var i=0;i<= 5 ;i++) 
{ 
    $('#' + 'btn' + i).Click() 
     /*Do your function*/ 

} 
1
$('.dropdown-menu li a').click(function(){ 
      $("#loading").fadeIn(); 
      var opts = { 
       lines: 10, // The number of lines to draw 
       length: 5, // The length of each line 
       width: 4, // The line thickness 
       radius: 10, // The radius of the inner circle 
       color: '#000', // #rgb or #rrggbb 
       speed: 1, // Rounds per second 
       trail: 60, // Afterglow percentage 
       shadow: false, // Whether to render a shadow 
       hwaccel: false // Whether to use hardware acceleration 
      }; 
      var target = document.getElementById('loading'); 
      var spinner = new Spinner(opts).spin(target); 
     }); 
関連する問題