我有這樣的一些HTML:如何在代理內的列表項中獲取元素的內部HTML?
<li eventId="123">
<img src="image.jpeg"/>
<h3 id="eventName">Event Name</h3>
<p id="eventDescription"></p>
</li>
我希望能夠通過jQuery拔出<h3>
和<p>
,這樣我就可以更新他們的價值觀。
我綁定到列表項的委託,並點擊我試圖用搶的<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");
}
難道我能做到這一點?
請記住接受[answer](http://stackoverflow.com/a/11780851/144665)。 :) – iambriansreed 2012-08-02 15:33:43
對不起,但你知道'$(this).get(X).getAttribute('foo')'實際上在做什麼嗎?因爲你在第二和第三種情況下完全錯誤地使用它。您可能想閱讀'.get':http://api.jquery.com/get/和'.getAttribute':https://developer.mozilla.org/en/DOM/element.getAttribute。 – 2012-08-02 15:41:32
@FelixKling你對[我的解決方案](http://stackoverflow.com/a/11780851/144665)有什麼看法? – iambriansreed 2012-08-02 15:48:50