您的位置:首页 > Web前端 > HTML

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

2020-02-02 08:37 1661 查看

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>

转载于:https://www.cnblogs.com/YangMT/p/4863814.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
amwxytu75574 发布了0 篇原创文章 · 获赞 0 · 访问量 111 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐