');
node = node.firstChild();
node.setStyle('border','2px solid #ccc');
equals(node.getAttr('style'),'border:2px solid #ccc;color:#ccc','修改样式中的一个');
node.setStyle({
'font':'12px',
'background':'#ccc'
});
equals(node.getAttr('style'),'background:#ccc;font:12px;border:2px solid #ccc;color:#ccc','添加新样式');
node.setStyle({
'font':'',
'background':'',
'border':'',
'color':''
});
equals(node.getAttr('style'),undefined,'清空样式');
node.setStyle('border','');
equals(node.getAttr('style'),"border:<script>alert("")</script>;",'脚本');
equals(node.toHtml(),'
','脚本转html');
node.innerHTML('
asdfasdfsdf
');
node.removeChild(node.firstChild(),true);
equals(node.toHtml(),'
asdfasdfsdf
','移除子节点');
node.innerHTML('
');
node.firstChild().setStyle('border');
equals(node.firstChild().toHtml(),'
','删除分号');
node.innerHTML('
');
equals(node.firstChild().toHtml(),'
');
node.innerHTML('
');
node.firstChild().setStyle('border');
equals(node.firstChild().toHtml(),'
');
node.innerHTML('
');
node.firstChild().setStyle('border');
equals(node.firstChild().toHtml(),'
');
node.firstChild().setStyle('color');
equals(node.firstChild().toHtml(),'
');
node.firstChild().setStyle('background-color');
equals(node.firstChild().toHtml(),'
');
});
test( 'getIndex', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
node.innerHTML('
asdfasdfsdf
')
node.removeChild(node.firstChild(),true);
var tmp = new UE.uNode.createElement('div');
node.appendChild(tmp);
equals(tmp.getIndex(),2,'节点索引');
});
test( 'traversal', function() {
var uNode = UE.uNode;
var node = uNode.createElement('div');
node.innerHTML('
asdfasdfsdf
')
var count = 0;
node.traversal(function(node){
count++;
});
equals(count,4);
count = 0;
node.traversal(function(node){
if(node.type == 'text'){
count++
}
});
equals(count,2);
node.traversal(function(node){
if(node.type == 'text'){
node.parentNode.removeChild(node)
}
});
equals(node.toHtml(),'
');
node.innerHTML('
asdfasdfsdf
');
node.traversal(function(node){
if(node.type == 'text'){
var span = uNode.createElement('span');
node.parentNode.insertBefore(span,node);
span.appendChild(node);
}
});
equals(node.toHtml(),'
');
});