123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- var RENDER_ELEMENT_WRAPPER = 'RENDER_ELEMENT_WRAPPER'; // 渲染评论的父标签
- var RENDER_ELEMENT_COMMENT = 'comment'; // 渲染评论的标签的 id
-
- /**
- * 根据 id 创建节点
- * @param {string} id id
- */
- function createElement(id) {
- var node = document.createElement('div');
- node.setAttribute("id", id);
- document.getElementById(RENDER_ELEMENT_WRAPPER).appendChild(node);
- }
-
- /**
- * 根据 id 删除子节点
- * @param {string} id id
- */
- function removeChild(id) {
- var myNode = document.getElementById(id);
- while (myNode.firstChild) {
- myNode.removeChild(myNode.firstChild);
- }
- }
-
-
-
- function main() {
- document.getElementById('render').addEventListener('click', function () {
- // 首先清空父标签的内容
- removeChild(RENDER_ELEMENT_WRAPPER);
-
- var id = RENDER_ELEMENT_COMMENT;
- // 动态创建渲染评论的标签
- createElement(id);
- // 渲染评论
- window.renderComment({
- id: id,
- type: 1,
- businessId: 'test',
- userId: 71299
- })
- })
-
- document.getElementById('re-render').addEventListener('click', function () {
- removeChild(RENDER_ELEMENT_WRAPPER)
- var id = RENDER_ELEMENT_COMMENT;
- createElement(id)
- window.renderComment({
- id: id,
- type: 1,
- businessId: 'test1',
- userId: 71299
- })
- })
-
- }
-
-
- main();
|