javascript的DOM操作(二)

<html>

<title>学习DOM</title>
<a id="wen">文本</a>

<input name="myinput" type="text">
<input name="myinput" type="text">

<input name="myinput" type="text">
<input name="myinput" type="text">

<script>
    /*
    //window下document的属性

    //cookie 属性可设置或查询与当前文档相关的所有 cookie。
    document.write(document.cookie);

    //domain 属性可返回下载当前文档的服务器域名。

    document.write(document.domain);        //localhost
   
    //lastModified 属性可返回文档最后被修改的日期和时间。

    document.write(document.lastModified); 
   
    
    //title 属性可返回当前文档的标题( HTML title 元素中的文本)。

    document.write(document.title);            //学习DOM

    //URL 属性可返回当前文档的 URL

    document.write(document.URL);            //http://localhost/js/dom/04.html
   
    //window下document的方法

    //getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用。
    var x = document.getElementById('wen');

    alert(x.innerHTML);                        //文本

    
    //getElementsByName() 方法可返回带有指定名称的对象的集合.

    var x = document.getElementsByName("myinput");
    alert(x.length);                        //4
    

    //getElementsByTagName() 方法可返回带有指定标签名的对象的集合

    var x = document.getElementsByTagName('input');
    alert(x.length);                        //4

        
    //open() 方法可打开一个新文档,并擦除当前文档的内容。

    //close() 方法可关闭一个由 document.open 方法打开的输出流,并显示选定的数据。
    var newDoc=document.open("text/html","replace");

    var txt="<html><body>Learning about the DOM is FUN!</body></html>";

    newDoc.write(txt);

    newDoc.close();
    
    
    //write() 方法可向文档写入 HTML 表达式或 JavaScript 代码。可列出多个参数(exp1,exp2,exp3,...) ,它们将按顺序被追加到文档中。

    document.write('嘻嘻','哈哈');                //嘻嘻哈哈


    //writeln() 方法与 write() 方法作用相同,外加可在每个表达式后写一个换行符。

    document.writeln('嘻嘻','哈哈');            //嘻嘻哈哈

*/
</script>

</html>



原文地址:https://www.cnblogs.com/aukle/p/3220205.html