Ext.DomHelper类的使用示例(内容操作)
?Ext.DomHelper类的使用示例(内容操作)?
?
- <mce:script?type="text/javascript"?><!--??
- Ext.DomHelper.append?内容追加??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?id="div1"?style="height:160px;padding:5px">原文本</div>'??
- ????????});??
- ????????Ext.DomHelper.append(Ext.get("div1"),"<br>新追加了文本",true);??
- ??????????
- Ext.DomHelper.applyStyles?样式追加??
- ????????????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?id="div1"?style="height:160px;padding:5px">原文本</div>'??
- ????????});??
- ??????????
- ??????????
- ??????????
- ????????Ext.DomHelper.applyStyles(Ext.get("div1"),"font-size:18px;color:green;font-weight:bold;");??
- ??????????
- ????????var?str?=?Ext.get("div1").dom.outerHTML;??
- ??????????
- ??????????
- ????????Ext.Msg.alert('DomHelper示例','<textarea?rows="6"?cols="35">'+str+'</textarea>');??
- ??????????
- Template.append?追加模板内容??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?id="div1"?style="height:160px;padding:5px">原文本</div>'??
- ????????});??
- ??????????
- ????????var?test?=?Ext.DomHelper.createTemplate('<div?name="{id}">'+??
- ????????????'<span?class="{cls}">{name:trim}?{value:ellipsis(10)}<br>第二行文本</span>'+??
- ????????????'</div>');??
- ??????????
- ????????test.append(Ext.get("div1"),{id:?'myid',?cls:?'myclass',?name:?'foo',?value:?'bar'},true);??
- ??
- Ext.DomHelper.insertAfter?后插新内容??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?id="div1"?style="height:60px;padding:5px;background-color:#D4D4D4">我是原来的Div对象</div>'??
- ????????});??
- ??????????
- ????????Ext.DomHelper.insertAfter(Ext.get("div1"),"<div?id='div2'?style='height:60px;padding:5px;background-color:#FEFCE7'>我是新追加的Div对象</div>");??
- ????});??
- ??????
- Ext.DomHelper.insertBefore?前插新内容??
- ??????????
- ????????Ext.DomHelper.insertBefore(Ext.get("div1"),"<div?id='div2'?style='height:60px;padding:5px;background-color:#FEFCE7'>我是新追加的Div对象</div>");??
- ??????????
- Ext.DomHelper.insertFirst?追加为第一个子元素??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?id="div1"?style="height:160px;padding:5px;><div?id="sub1">我是原来的Div的第一个子对象</div></div>'??
- ????????});??
- ??????????
- ????????Ext.DomHelper.insertFirst(Ext.get("div1"),"<div?id='div2'?style='height:60px;padding:5px;background-color:#D4D4D4'>我是新追加的Div对象</div>");??
- ????});??
- ??????
- Ext.DomHelper.insertHtml?插入HTML内容??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'280px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?style="height:160px;padding:5px;"><div?id="div1"?>我是原来的Div的第一个子对象</div></div>'??
- ????????});??
- ??????????
- ????????Ext.DomHelper.insertHtml("beforeBegin",document.getElementById("div1"),"我是新插入的Html文本");??
- ??????????
- Ext.DomHelper.overwrite?替换内容??
- ????Ext.onReady(function(){??
- ????????var?panel?=?new?Ext.Panel({??
- ????????????title?:?'Ext.DomHelper示例',??
- ????????????width?:?'220px',??
- ????????????renderTo?:?'sub1',??
- ????????????html?:?'<div?style="height:160px;padding:5px;"><div?id="div1"?>我是原来的Div的内容</div></div>'??
- ????????});??
- ??????????
- line-height: 18px; color: black; background