不好意思,刚用JS,有个问题想请教下applyChild(): Applends an element as a child to the object
applyElement(): Makes the element a child or parent of another element.applyChild()我会用,<ul id="list">
<li>1</li>
<li>2</li>
</ul>
<script>
    var item = document.createElement('li');
    item.innerHTML = '3';    var list = document.getElementById('list');
    item.appendElement(list);
</script>
但是applyElement()不知道怎么用,能不能请那位大哥给讲解下他们之间的区别能否给写行代码, 在我上面这个例子上也把 “3”加到<li></li>里么,非常感谢

解决方案 »

  1.   

     var list = document.getElementById('list');
    list.appendChild(item);
      

  2.   

    DOMDocument 属性和方法
      最近发现DOMDocument对象很重要,还有XMLHTTP也很重要注意大小写一定不能弄错.属性: 1Attributes     存储节点的属性列表(只读)
     2childNodes     存储节点的子节点列表(只读)
     3dataType     返回此节点的数据类型
     4Definition     以DTD或XML模式给出的节点的定义(只读)
     5Doctype     指定文档类型节点(只读)
     6documentElement     返回文档的根元素(可读写)
     7firstChild     返回当前节点的第一个子节点(只读)
     8Implementation     返回XMLDOMImplementation对象
     9lastChild     返回当前节点最后一个子节点(只读)
    10nextSibling     返回当前节点的下一个兄弟节点(只读)
    11nodeName     返回节点的名字(只读)
    12nodeType     返回节点的类型(只读)
    13nodeTypedValue     存储节点值(可读写)
    14nodeValue     返回节点的文本(可读写)
    15ownerDocument     返回包含此节点的根文档(只读)
    16parentNode     返回父节点(只读)
    17Parsed     返回此节点及其子节点是否已经被解析(只读)
    18Prefix     返回名称空间前缀(只读)
    19preserveWhiteSpace     指定是否保留空白(可读写)
    20previousSibling     返回此节点的前一个兄弟节点(只读)
    21Text     返回此节点及其后代的文本内容(可读写)
    22url     返回最近载入的XML文档的URL(只读)
    23Xml     返回节点及其后代的XML表示(只读)方法: 1appendChild     为当前节点添加一个新的子节点,放在最后的子节点后
     2cloneNode     返回当前节点的拷贝
     3createAttribute     创建新的属性
     4createCDATASection     创建包括给定数据的CDATA段
     5createComment     创建一个注释节点
     6createDocumentFragment     创建DocumentFragment对象
     7createElement     创建一个元素节点
     8createEntityReference     创建EntityReference对象
     9createNode     创建给定类型,名字和命名空间的节点
    10createPorcessingInstruction     创建操作指令节点
    11createTextNode     创建包括给定数据的文本节点
    12getElementsByTagName     返回指定名字的元素集合
    13hasChildNodes     返回当前节点是否有子节点
    14insertBefore     在指定节点前插入子节点
    15Load     导入指定位置的XML文档
    16loadXML     导入指定字符串的XML文档
    17removeChild     从子结点列表中删除指定的子节点
    18replaceChild     从子节点列表中替换指定的子节点
    19Save     把XML文件存到指定节点
    20selectNodes     对节点进行指定的匹配,并返回匹配节点列表
    21selectSingleNode     对节点进行指定的匹配,并返回第一个匹配节点
    22transformNode     使用指定的样式表对节点及其后代进行转换
    23transformNodeToObject     使用指定的样式表将节点及其后代转换为对象
      

  3.   

    难道是我out了,我没有见过applyChild(),applyElement()。appendChild()倒是有。
      

  4.   

    抄来的
    applyElement方法
    语法:
    object . applyElement ( oElement , sWhere )
    参数:
    oElement :  必选项。对象(Element)。要被添加的对象。
    sWhere :  可选项。字符串(String)。outside | inside :
                          outside : 默认值。将 oElement 添加为 object 的父对象。
                          inside :  将 oElement 添加为 object 的子对象。但 oElement 将成为object 的原所有子对象的父对象。If you call the applyElement method on an element that was created with the createElement method, but not yet added to the document tree, the element will lose the contents of its innerHTML property.
        不能使用element会失去innerHTML属性,所以没有效果
        我试了下,确实没什么用,还是用appendChild吧.
         
            var item = document.createElement('li');
        item.innerHTML = '3';    var list = document.getElementById('list');
        //item.applyElement(list,"outside");
        //list.applyElement(item,"inside");
        list.appendChild(item);
         
        
      

  5.   

    applyElement只支持IE,其它浏览器不支持。
    看看这个例子就明白怎么用:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <script>
    function rdl_doApply(e){
    with (document.getElementById("oSelect1")) var sParam1=options[selectedIndex].value;
    with (document.getElementById("oSelect2")) var sParam2=options[selectedIndex].value;
    var oNewNode=document.createElement(sParam1);
    document.getElementById("oList").applyElement(oNewNode,sParam2);
    rdl_doCode();
    }
    function rdl_doCode(){
    document.getElementById("oView").innerText=document.getElementById("oCode").innerHTML;
    }
    window.onload=rdl_doCode;
    </script>
    <div id=oCode>
    <ul id=oList>
    <li>列表项目1</li>
    <li>列表项目2</li>
    </ul>
    </div>
    <table height=56>
    <tr>
    <td>
    <select style="width:100px;" id="oSelect1">
    <option value="button" >button</option>
    <option value="textarea" selected>textarea</option>
    </select>
    </td>
    <td>
    <select style="width:100px;" id="oSelect2">
    <option value="outside" selected>outside</option>
    <option value="inside">inside</option>
    </select>
    </td>
    <td>
    <input type=button value=" 添加 " onclick="rdl_doApply()">
    </td>
    </tr>
    </table>
    <div id=oView style="width:80%;font-size:10px;line-height:16px;background:#DFDFDF;padding:8px;"></div>
    </body>
    </html>
      

  6.   

    To datiexiong: "If you call the applyElement method on an element that was created with the createElement method, but not yet added to the document tree, the element will lose the contents of its innerHTML property."你一下就点中要开了,非常感谢