gpt4 book ai didi

javascript - 为主菜单中所有 'a'标签添加点击事件

转载 作者:搜寻专家 更新时间:2023-11-01 05:01:14 24 4
gpt4 key购买 nike

$(document).ready(function () {
$("#MainMenu a").click(function () {
$("#divContent").load( ???? );
});
});

我想从我的主菜单中检索所有链接,将 click 事件附加到它们,并告诉 jQuery 通过 ajax 调用将一些内容加载到 #divContent。内容位置当然应该取决于每个链接中的 href 标签。

最佳答案

你快到了,尝试:

 $("#MainMenu a").click(function (e) {
e.preventDefault(); //prevent the default click behavior of the anchor.
$("#divContent").load(this.href); //just get the href of the anchor tag and feed it onto load.
});

关于javascript - 为主菜单中所有 'a'标签添加点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18949990/

24 4 0