[英]assign dynamic id to jquery
I have 4 links which has different id, How to assign different id into jquery when i click one of the link? 我有4个具有不同ID的链接,当我单击链接之一时如何将不同的ID分配给jquery? Any guidance is highly appreciate.
任何指导都非常感谢。 Thanks!
谢谢!
Html: 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: 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);
});
});
将$(*assign id here*)
更改$(*assign id here*)
$('a[id^="btn"]')
或$('.dropdown-menu li a')
$('.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);
});
You can dynamically check the id's in the following way. 您可以通过以下方式动态检查ID。 Put it in for loop or in the $each func and add the following
将其放入for循环或$ each函数中,并添加以下内容
eg :: 例如::
for(var i=0;i<= 5 ;i++)
{
$('#' + 'btn' + i).Click()
/*Do your function*/
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.