我是javascript的新手,我已经使用getelement通过id检索了一些数据,现在我想要一个使用getelementbytagname的特定部分
document.getElementById('titleUserReviewsTeaser').innerHTML;
"
<h2>User Reviews</h2>
<div class="user-comments">
<div class="tinystarbar" title="10/10">
<div style="width: 100px;"> </div>
</div>
<span itemprop="review" itemscope="" itemtype="http://schema.org/Review">
<strong itemprop="name">Awesome review for an awesome movie</strong>
<span itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content="1">
<meta itemprop="ratingValue" content="10">
<meta itemprop="bestRating" content="10">
</span>
<div class="comment-meta">
25 August 2005 | by <a href="/user/ur6899565/?ref_=tt_urv"><span itemprop="author">Dragondrawer88</span></a>
<meta itemprop="datePublished" content="2005-08-25">
(United States)
– <a href="/user/ur6899565/comments?ref_=tt_urv">See all my reviews</a>
</div>
<div>
<p itemprop="reviewBody">Balto has been a favorite movie of mine ever since it came out. This is the touching story of an out casted half dog half wolf named Balto voiced by the talented Kevin Bacon who's voice added a slight charm to the Balto character. The story takes place in Nome Alaska in the year 1925. A sickness as stricken the town's children and with out the antitoxin which is located hundreds of miles away in town of Nanana, the children will surly die. The dog team sent to retrieve the medicine which is led by Balto's almost arch nemesis Steel, is lost in a horrible snow storm. Now it is up to Balto to find the missing sled dog team and bring the medicine back to Nome before it is too late.<br><br>This movie is so gripping, I can never sit through the whole thing without balling my eyes out. This movie has a great plot which is based of a true story, a wonderful cast of voice actors, and a vary flowing animation style. This movie is so gripping and compelling that it as inspired me to become an cartoonist. I loved this movie so much that some how I found out I have three copies of it in my movie library. Surly this movie is worth seeing or owning if it makes a 17 year old shows tears for it, or sets the course for his career. Call me a geek but this movie is perfect for any one who likes talking animals, old school basic animation, and happy endings.</p>
</div>
</span>
<hr>
<div class="yn" id="ynd_1158238">
17 of 20 people found this review helpful.
Was this review helpful to you?
<button class="btn small" value="Yes" name="ynb_1158238_yes" onclick="CS.TMD.user_review_vote(1158238, 'tt0112453', 'yes');">Yes</button>
<button class="btn small" value="No" name="ynb_1158238_no" onclick="CS.TMD.user_review_vote(1158238, 'tt0112453', 'no');">No</button>
</div>
<div class="see-more">
<a href="/title/tt0112453/reviews-enter?ref_=tt_urv" rel="login" class="cboxElement">Review this title</a>
<span>|</span>
<a href="/title/tt0112453/reviews?ref_=tt_urv">See all 78 user reviews</a> »
</div>
</div>
"
现在我想要p itemprop =“reviewBody”和/ p标签之间的数据我该怎么做?
答案 0 :(得分:1)
document.getElementById('titleUserReviewsTeaser').innerHTML.getElementByTagName("p");
首先,getElementByTagName
不存在。多个元素可以具有相同的标记名称,因此函数为getElementsByTagName
(复数!)并返回NodeList。
其次,innerHTML
是一个字符串。它不是DOM节点。您需要在DOM节点上调用getElementsByTagName
。
document.getElementById('titleUserReviewsTeaser').getElementsByTagName("p")
答案 1 :(得分:-1)
试试这个:
alert(document.getElementsByTagName("p")[0].innerHTML);