1
<html>
<head></head>
<body>
<div class="mtb-desc">
    some contentsome contentsome contentsome  contentsome contentsome contentsome contentsome content.

    some contentsome contentsome contentsome entsome contentsome contentsome contentsome contentsome.

    NO : 212122Name is Jone</div>
<span class="mtb-price">
<label Class="mtb-ofr"><b class="lb1"></b>WWWW</label></span>
<script>
var eg1 = document.querySelectorAll('.mtb-desc')[0].childNodes[0].split(null)[1].nodeValue;
var eg2 = document.querySelectorAll('.mtb-ofr')[0].childNodes[1].nodeValue = eg1;
alert(eg2);
</script>
</body>
</html>

在上面的代码中,我想用文本 Name is Jone 替换 WWWW。那么我如何从该文本节点访问“Name is Jone”文本?

4

1 回答 1

1

要匹配结尾的非数字文本并将其插入 WWWW 所在的位置,请执行以下操作:

var content = document.querySelectorAll('.mtb-desc')[0].innerText;
var insertion = content.match(/[^0-9]+$/)[0];
document.querySelectorAll('.mtb-ofr')[0].innerText = insertion;
于 2012-06-23T05:35:31.773 回答