我正在尝试使用“.comments”中的值创建一个变量,然后在“4 个评论”之前添加“阅读全部”一词。最后,将新变量附加到“#comments”。
设法编写一些东西,但它正在移动现有对象,而不是使用现有对象的值创建一个新对象。
下面的一些代码
<script type="text/javascript">
var commentsLink = document.querySelector('.story .comments a'),
commentsSubmit = document.querySelector('#comments .form-item-submit');
commentsLink.innerHTML = 'Read all ' + commentsLink.innerHTML;
commentsLink.className += 'readComments';
commentsSubmit.appendChild(commentsLink);
</script>
<div class="story">
<div class="comments">
<a href="http://foo.com">4 comments</a>
</div>
</div>
<div id="comments">
<div class="form-item-submit">Submit</div>
</div>
期望的结果:
<div class="story">
<div class="comments">
<a href="http://foo.com">4 comments</a>
</div>
</div>
<div id="comments">
<div class="form-item-submit">Submit</div>
<a href="http://foo.com" class="readComments">Read all 4 comments</a>
</div>
任何人都可以对此有所了解吗?请不要使用Jquery。