提交 6401e7fb 编写于 作者: C campaign

by zhanyi

上级 2a38391d
...@@ -190,12 +190,22 @@ ...@@ -190,12 +190,22 @@
return tmpRoot.toHtml(); return tmpRoot.toHtml();
} }
}, },
innerText:function () { innerText:function (textStr) {
if (this.type != 'element' || dtd.$empty[this.tagName]) { if (this.type != 'element' || dtd.$empty[this.tagName]) {
return this; return this;
} }
var html = this.toHtml(); if (textStr) {
return html.replace(/<[^>]+>/g, ''); if(this.children){
for (var i = 0, ci; ci = this.children[i++];) {
ci.parentNode = null;
}
}
this.children = [];
this.appendChild(uNode.createText(textStr));
return this;
} else {
return this.toHtml().replace(/<[^>]+>/g, '');
}
}, },
getData:function () { getData:function () {
if (this.type == 'element') if (this.type == 'element')
......
...@@ -25,7 +25,7 @@ test( 'getNodesByTagName', function() { ...@@ -25,7 +25,7 @@ test( 'getNodesByTagName', function() {
var node = uNode.createElement('<div id="aa"><div id="bb"><div id="cc"></div> </div>sdfadf</div>'); var node = uNode.createElement('<div id="aa"><div id="bb"><div id="cc"></div> </div>sdfadf</div>');
var nodelist = node.getNodesByTagName('div'); var nodelist = node.getNodesByTagName('div');
equals(nodelist.length,2,'div节点列表长度'); equals(nodelist.length,2,'div节点列表长度');
equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div id="bb"><div id="cc"></div> </div>sdfadf','innerHTML内容'); equals(node.innerHTML().replace(/[ ]+>/g,'>'),'<div id="bb"><div id="cc"></div></div>sdfadf','innerHTML内容');
}); });
test( 'innerHTML', function() { test( 'innerHTML', function() {
...@@ -38,6 +38,9 @@ test( 'innerHTML', function() { ...@@ -38,6 +38,9 @@ test( 'innerHTML', function() {
ci.tagName = 'p'; ci.tagName = 'p';
} }
equals(node.innerHTML(),'<p><p><p></p></p></p>','innerHTML内容'); equals(node.innerHTML(),'<p><p><p></p></p></p>','innerHTML内容');
node = uNode.createElement('<div></div>');
node.innerHTML('asdf');
equals(node.innerHTML(),'asdf','innerHTML内容');
}); });
test( 'innerText', function() { test( 'innerText', function() {
...@@ -51,6 +54,8 @@ test( 'innerText', function() { ...@@ -51,6 +54,8 @@ test( 'innerText', function() {
var node = uNode.createElement('<div id="aa">sdfadf</div>'); var node = uNode.createElement('<div id="aa">sdfadf</div>');
node.innerHTML('<p>dfsdfsdf<b>eee</b>sdf</p>'); node.innerHTML('<p>dfsdfsdf<b>eee</b>sdf</p>');
equals(node.innerText(),'dfsdfsdfeeesdf','获取标签中纯文本'); equals(node.innerText(),'dfsdfsdfeeesdf','获取标签中纯文本');
node.innerText('sdf');
equals(node.innerHTML(),'sdf','设置文本节点');
}); });
test( 'getData', function() { test( 'getData', function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册