为jquery分配动态id
assign dynamic id to jquery
我有4个链接,它们有不同的id,当我点击其中一个链接时,如何将不同的id分配到jquery中?非常感谢任何指导。谢谢
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);
});
});
将$(*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);
});
您可以通过以下方式动态检查id。将其放入for循环或$each函数中并添加以下
例如:
for(var i=0;i<= 5 ;i++)
{
$('#' + 'btn' + i).Click()
/*Do your function*/
}
相关文章:
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 在iframe代码中动态插入子id
- 如何为动态创建的元素分配唯一的id-Javascript
- 使用getElementById设置动态ID的输入字段的样式
- Php,Javascript-动态表单id's和动态验证
- 动态添加id's到输入字段
- Javascript:获取具有动态id的文本框值
- 如何将value和id动态添加到html下拉选项标记中
- Jquery通过id动态选择对象使用字符串
- 根据ID动态创建元素(Jquery)
- 如何最好地搜索基于特定元素的id动态生成的自定义列表?
- 使用jQuery通过ID动态修改元素属性
- Jquery getjson为每个id动态点击时- ruby on rails
- 通过id动态访问对象数据
- 在d3.js中使用县Id动态地在地图中插入圆圈
- 使用jQuery将ID动态分配给当前表行tr
- 使用Jquery根据可拖放对象的ID动态更改图像的src
- 如何将id动态添加到每个蓝色圆圈中
- 如何通过id动态选择JQuery元素
- 如何设置ID动态创建的文本框在JavaScript