为什么按钮不消失?

来源:9-16 创建元素节点createElement

慕少8622884

2016-01-11 16:14

请问为什么我的代码结果中的按钮不消失呢?

写回答 关注

2回答

  • yes居然被占用
    2016-01-11 17:05:22
    已采纳

    下面代码是可以的

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">

    <title>Insert title here</title>

    </head>

    <body>

    <input id="but" type="button" value="创建链接" onclick="createa('http://www.imooc.com','慕课网')" />

    <script type="text/javascript">

    var main = document.body;

    //创建链接

    function createa(url,text)

    {

        var a = document.createElement("a");

        a.setAttribute("href",url);

        a.innerHTML = text;

        main.appendChild(a);

        var h = document.getElementById("but");

        h.style.display = 'none';

    }

    // 调用函数创建链接

    // main.appendChild(createa("http://www.imooc.com","慕课网"));


    </script> 

    </body>

    </html>


    慕少8622...

    非常感谢!

    2016-01-11 18:48:34

    共 1 条回复 >

  • 愁晴
    2016-01-11 16:20:42

    你对按钮没有消失的代码操作

    慕少8622...

    非常感谢!

    2016-01-11 18:49:06

    共 1 条回复 >

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467402 学习 · 21877 问题

查看课程

相似问题