gpt4 book ai didi

javascript - 如何在委托(delegate)中获取列表项内元素的内部 HTML?

转载 作者:行者123 更新时间:2023-11-30 08:57:59 25 4
gpt4 key购买 nike

我有这段 HTML :

<li eventId="123">
<img src="image.jpeg"/>
<h3 id="eventName">Event Name</h3>
<p id="eventDescription"></p>
</li>

我希望能够拉出 <h3><p>通过 jQuery 以便我可以更新它们的值。

我有一个绑定(bind)到列表项的代理,单击时我试图捕获 <h3><p>使用:

function eventIdClicked()
{
// This gets hold of "123" OK
theEvent.id = $(this).get(0).getAttribute('eventId');

// How to get the other 2 inner html?
var existingEventName = $(this).get(1).getAttribute('eventName');
var existingEventDesc = $(this).get(2).getAttribute('eventDescription');
$.mobile.changePage("home.html");
}

我能做到吗?

最佳答案

可能像 $(this).find("h3").text()$(this).find("p").text()?

非常简单的 jquery。

此外,虽然在这种情况下它不会影响代码,但 ID 必须是唯一的。

如果 ID 不是唯一的,则元素也可能没有 ID。

关于javascript - 如何在委托(delegate)中获取列表项内元素的内部 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11780651/

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