我有这个数组:
var arr = ['<p id="p1">Paragraph 1<p>', '<p id="p2">Paragraph 2<p>', '<p id="p3">Paragraph 3<p>']
如何从此数组中获取文本Paragraph 3
?
答案 0 :(得分:4)
答案 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>