12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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',
- API: 'http://api.links123.net/comment/v1', // API 前缀, 默认 http://api.links123.net/comment/v1
- })
- })
-
- 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',
- API: 'http://api.links123.net/comment/v1', // API 前缀, 默认 http://api.links123.net/comment/v1
- })
- })
-
- }
-
-
-
- main();
|