1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- var COMMENT_URL = '../static/js/comment.0.5.13.js';
- var RENDER_ELEMENT_COMMENT = 'comment'; // 渲染评论的标签的 ID
-
- /**
- * 异步加载 js 文件
- * @param {string} url 需要加载的 js 文件地址
- * @param {function} callback js 文件加载后的回调
- */
- function loadScript(url, callback){
- var script = document.createElement("script")
- script.type = "text/javascript";
-
- if (script.readyState){ //IE
- script.onreadystatechange = function(){
- if (script.readyState == "loaded" ||
- script.readyState == "complete"){
- script.onreadystatechange = null;
- callback();
- }
- };
- } else { //Others
- script.onload = function(){
- callback();
- };
- }
-
- script.src = url;
- document.getElementsByTagName("head")[0].appendChild(script);
- }
-
-
- /**
- * 渲染评论组件搭配指定的节点
- * @param {string} id element id
- * @param {string} type 评论的 type
- * @param {string} businessId 评论的 businessId
- */
- function render(id, type, businessId) {
- loadScript(COMMENT_URL, function() {
- window.renderComment({
- id: id,
- type: type,
- businessId: businessId
- })
- })
- }
-
-
- document.getElementById('render').addEventListener('click', function() {
- render(RENDER_ELEMENT_COMMENT, 1, 'test');
- })
-
- document.getElementById('re-render').addEventListener('click', function() {
- render(RENDER_ELEMENT_COMMENT, 1, 'test1');
- })
-
-
-
|