asp学习网: 首页 >> javascript教程 >> Dhtml教程 >> mergeAttributes方法

mergeAttributes方法

语法:
object . mergeAttributes ( oSource , bPreserve )
参数:
oSource :  IE5.0 必选项。对象(Element)。指定属性要被复制到 object 的对象。
bPreserve :  IE5.5 可选项。布尔值(Boolean)。false | true false :  不保护目标对象 object 的身份属性。
true :  默认值。保护目标对象 object 的身份属性。


返回值:

说明:
复制 oSource 的所有可读写属性到 object 。包括持久的 HTML 属性,事件( event ),和样式。
在 IE5.0 及之前的版本中,只读属性不会被复制。如 id 属性。
在 IE5.5+ 中,通过设置 bPreserve 参数值为 false ,可以使 oSource 的所有属性被复制到 object 。包括 ID 属性和 NAME 属性。



<script>
var sCode="<font name=rdl2 id=idFont2>我是目标对象。</font>";

var oCodeDiv;
var oFont;

function window.onload(){
oCodeDiv=document.all("idCodeDiv");
oFont1=document.all("idFont1");
oFont2=document.all("idFont2");
with (oFont1) title=outerHTML;
oCodeDiv.innerText=sCode;
}

function doMerge(){
var bPreserve;
with (document.all("idSel")) if(options[selectedIndex].value=="false") bPreserve=false;else bPreserve=true;
oFont1.removeAttribute("title");
oFont2.mergeAttributes(oFont1,bPreserve);
oCodeDiv.innerText=oFont2.outerHTML;
}

function doReset(){
window.location.reload();
}

</script>


<font name=rdl1 id=idFont1 color=red style="font-weight:bold" case=died onmouseover="this.style.color='blue';" onmouseout="this.style.color='black';">我的所有属性将被复制到目标对象。</font>
<br><br>
<font name=rdl2 id=idFont2>我是目标对象。</font>
<br><br>
<select id="idSel">
<option value="" style="font-weight:bold;">---bPreserve---
<option value="true">true
<option value="false">false
</select>
<input type=button value="复制属性" onclick="doMerge();"><input type=button value="全部复位" onclick="doReset();">
<br><br><div id=idCodeDiv></div>

from:asp学习网/title:mergeAttributes方法/ time:2007-10-15 23:12:56

本文主题mergeAttributes

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行