gpt4 book ai didi

javascript - 将动态 id 分配给 jquery

转载 作者:行者123 更新时间:2023-11-30 16:11:33 26 4
gpt4 key购买 nike

我有 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>

J查询:

$(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')

关于javascript - 将动态 id 分配给 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36171712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com