diff --git a/build/MDEditor.min.js b/build/MDEditor.min.js index 909f627..1a6c250 100644 --- a/build/MDEditor.min.js +++ b/build/MDEditor.min.js @@ -900,9 +900,10 @@ } MDEditor.prototype = { load: function() { + if (!this.obj) return; var self = this, box = self.obj[0], index = 0; if (box) { - if (box.innerHTML !== "") self.opts.value = box.innerHTML.replace(/\>\;/g, ">").replace(/\<\;/g, "<"), + if (box.children.length > 0) self.opts.value = box.children[0].innerHTML.replace(/\>\;/g, ">").replace(/\<\;/g, "<"), box.innerHTML = ""; box.appendChild(self.preview_el), box.appendChild(self.tools), box.appendChild(self.textarea); } diff --git a/lib/MDEditor.js b/lib/MDEditor.js index 12c9303..a40b76b 100644 --- a/lib/MDEditor.js +++ b/lib/MDEditor.js @@ -144,13 +144,13 @@ MDEditor.prototype = { //加载编辑器 load:function(){ + if(!this.obj) return; var self = this,box = self.obj[0],index=0; if(box) { - if(box.innerHTML!=="") - self.opts.value = box.innerHTML - .replace(/\>\;/g,'>') - .replace(/\<\;/g,'<'), + if(box.children.length>0) + self.opts.value = box.children[0].innerHTML + .replace(/\>\;/g,'>').replace(/\<\;/g,'<'), box.innerHTML=''; box.appendChild(self.preview_el), box.appendChild(self.tools),