gpt4 book ai didi

jquery - 将变量传递给 Jquery 函数

转载 作者:行者123 更新时间:2023-12-01 02:07:19 25 4
gpt4 key购买 nike

我有一个项目列表,我想对其执行相同的操作。它们都有单独的 ID,因此我希望能够将每个 ID 的名称传递给 Jquery,以便仅对该 ID 执行操作。例如:

<a href="#" id="1">one</a>
<a href="#" id="2">two</a>
<div id="#test1"></div>
<div id="#test2"></div>

我希望能够做这样的事情:

function doSomething(x) {
var div=x+'div';
$(x).click(function() { $.(div).slideDown(); });
}

有什么想法吗?

谢谢。

最佳答案

<a href="#" class="x" d="test1">one</a>
<a href="#" class="x" d="test2">two</a>
<div id="test1" class="x"></div>
<div id="test2" class="x"></div>
function doSomething(x) 
{
$("a.x").click(function()
{ $( "div#" + $(this).attr("d") ).slideDown(); }
);
}

关于jquery - 将变量传递给 Jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9222020/

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