DOM操作html、css

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>事件</title>

</head>
<body>
    <p id="pid">hello</p>
    <a id="aid" href="http://www.baidu.com">Hello</a>
    <button οnclick="demo()">button</button>
    <script>
        function demo()
        {
          // var nv= document.getElementById("pid"); 注释掉的只是证明绝不要在文档加载完使用这个document.write()会覆盖文档
         //   nv.innerHTML="World";
           /// document.getElementsByTagName("p");//选择相同元素的第一个
            document.getElementById("aid").href="http://www.jikexueyuan.com";//本题使用的是链接 图片等同理

        }
    </script>
</body>
</html>
改css:<pre name="code" class="html"><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>事件</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div  id="div" class="div">
        Hello
    </div>
    <button οnclick="demo()">button</button>
    <script>
        function demo()
        {
            document.getElementById("div").style.background="red";//是引号!!
        }
    </script>
</body>
</html>

EventListener句柄:
<pre name="code" class="html"><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>事件</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <p id="pid">hello</p>
    <button id="btn">butn</button>
<script>
    document.getElementById("btn").addEventListener("click",function(){
        alert("world")
    })
</script>
</body>
</html>


<pre style="font-family: 宋体; font-size: 12pt; background-color: rgb(255, 255, 255);"><pre name="code" class="html"><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>事件</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <p id="pid">hello</p>
    <button id="btn">butn</button>
<script>
    var x=document.getElementById("btn");
    x.addEventListener("click",hello);
    x.addEventListener("click",world);
    x.removeEventListener("click",world);
    function hello(){
        alert("hello");
    }
    function world(){
        alert("world");
    }
</script>
</body>
</html>




全部评论

相关推荐

稚名不带撇:感觉学院本就已经废了,不是能不能进公司的问题了,是根本就没有啥面试,boss沟通了一千多,回我消息的才89,面试的才二十几个,但基本上都是小公司点击就送,唯一一次有1000+的公司面试,面的很好全回答出来了,项目这块个人感觉也说的不错,甚至面试官最后还直接给我介绍公司业务和看公司系统这些,介绍的也比较详细,说了40分钟到一个小时左右,说怕给我offer我不喜欢这种模式啥啥啥的,鼠鼠以为应该稳了,但是最后还是挂了,我问我们老师他说这种情况大概率是学历比你高的出现了,虽然可能问题没有全回答出来,但是学历把你爆了
秋招,不懂就问
点赞 评论 收藏
分享
真的很糟糕:约等于,凡事不能太绝对
听劝,这个简历怎么改
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务