• DOM对象操作HTML元素和消息对话框(alert,confirm,prompt)(一)


    DOM对象操作HTML元素和消息对话框(alert,confirm,prompt)
    <head>
        <meta charset="UTF-8">
        <title>DOM对象操作HTML元素和消息对话框</title>
    </head>
    <body>
    <p name="pn">hello</p>
    <p name="pn">hello</p>
    <p name="pn">hello</p>
    <p name="pn">hello</p>

    <a id="aid" title="你点击了我">hello world</a>

    <ul>
        <li>第一个</li>
        <li>第二个</li>
        <li>第三个</li>
        <li>第四个</li>
    </ul>
    <ul>
        <li>第一个</li>
        <li>第二个</li>
        <li>第三个</li>
        <li>第四个</li>
    </ul>

    <script>
        function getByName(){
            var pname=document.getElementsByName("pn");
            alert(pname.length);
            var pnode=pname[2];
            pnode.innerHTML=window.prompt("提示","请输入你的姓名");

            var yesorno=window.confirm("单击“确定”继续。单击“取消”停止。");
            if(yesorno){
                alert("欢迎你访问我们的web主页");
            }
            else{
                alert("你看到这么华丽的界面,你舍得退出吗");
            }
        }

        function getByTagName(){
            var ptagname=document.getElementsByTagName("p");
            alert(ptagname.length);
            var pnode=ptagname[1];
            pnode.innerHTML=window.prompt("提示","请输入内容");

        }
        function getAttribute(){
            var anode=document.getElementById("aid");
            var attr=anode.getAttribute("title");
            alert(attr);

        }
        function setAttribute(){
            var anode=document.getElementById("aid");
            var attr=anode.setAttribute("title","动态修改了title属性内容");
            var attr=anode.getAttribute("title");
            alert(attr);
        }

        function getChildNode(){
            var childnode=document.getElementsByTagName("ul")[0].childNodes;
            alert(childnode.length);
        }
        //getByName();
        //getByTagName();
        //getAttribute();
        //setAttribute();
        getChildNode();
    </script>
    </body>

  • 相关阅读:
    学习Node.js笔记(一)
    HTML5的新特性及技巧分享总结
    前端切图的一些笔记(整理的有点乱)
    聊一聊前端速度统计(性能统计)那些事儿(转)
    jQuery中的checkbox问题
    随笔记录
    pillow模块快速学习
    Git学习及使用
    网站(陆续更新)
    ggplot笔记001——ggplot2安装
  • 原文地址:https://www.cnblogs.com/YangMT/p/4863814.html
Copyright © 2020-2023  润新知