如何在数组中获取文本?

时间:2013-04-22 16:39:00

标签: javascript jquery return-value paragraph xgettext

我有这个数组:

var arr  = ['<p id="p1">Paragraph 1<p>', '<p id="p2">Paragraph 2<p>', '<p id="p3">Paragraph 3<p>']

如何从此数组中获取文本Paragraph 3

2 个答案:

答案 0 :(得分:4)

您可以使用:

$(arr[2]).prop('innerHTML');

或:

$(arr[2]).html();

<强> Fiddle

答案 1 :(得分:1)

您可以使用split()方法剪切字符串来删除内部文本。

<script>

var arr  = ['<p id="p1">Paragraph 1<p>', '<p id="p2">Paragraph 2<p>', '<p id="p3">Paragraph 3<p>']

/* Even works with closed <p> element */

var arr  = ['<p id="p1">Paragraph 1</p>', '<p id="p2">Paragraph 2</p>', '<p id="p3">Paragraph 3</p>']

alert(arr[2].split('>')[1].split('<')[0])
</script>