4-1里面的为什么我怎么编译都是出不来效果,复制别人也不行

来源:4-1 编程挑战

慕粉3648130

2016-08-07 17:49

这里面需要练习的代码为什么我一个也实现不出来

写回答 关注

6回答

  • 慕慕mu
    2016-08-10 14:59:04

    应该是你的某一个地方写错了,看看JS里是不是的符号有没有错,或者input里的onclick有没有写错,函数后面有没有把括号带上等,应该是一些小错误造成的,如果全选复制别人的应该是可以的。下面这个是我写的

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
    <title>javascript</title>
    <style type="text/css">
    body{font-size:12px;}
    #txt{
        height:400px;
        width:600px;
     border:#333 solid 1px;
     padding:5px;}
    p{
     line-height:18px;
     text-indent:2em;}
    </style>
    </head>
    <body>
      <h2 id="con">JavaScript课程</H2>
      <div id="txt">
         <h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>
            <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>
            <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>
            <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>
      </div>
      <form>
      <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
        <input type="button" value="改变颜色" onClick="chanColor()" > 
        <input type="button" value="改变宽高" onClick="chanWidth()" >
        <input type="button" value="隐藏内容" onClick="chanNone()" >
        <input type="button" value="显示内容" onClick="chanBlock()">
        <input type="button" value="取消设置" onClick="chanQx()" >
      </form>
      <script type="text/javascript">
            //定义"改变颜色"的函数
           
            var txt = document.getElementById("txt");
           
            function chanColor(){
                txt.style.color="blue";
                txt.style.backgroundColor="#ccc"; 
            };
           
            //定义"改变宽高"的函数
            function chanWidth(){
                txt.style.width="200"+"px";
                txt.style.height="400"+"px";          
            };
           
            //定义"隐藏内容"的函数
            function chanNone(){
                txt.style.display="none";              
            };
           
            //定义"显示内容"的函数
            function chanBlock(){
                txt.style.display="block";                
            };
           
            //定义"取消设置"的函数"
            function chanQx(){
                var mychose = confirm("确定要取消所有设置吗?");
                if(mychose==true){
                   txt.removeAttribute("style");
                }
            }
      </script>
    </body>
    </html>


  • qq_杺難幵_03727737
    2016-08-09 15:29:04

    <!DOCTYPE HTML>

    <html>

    <head>

    <meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />

    <title>javascript</title>

    <style type="text/css">

    body{

        font-size:12px;

    }

    /*#con{

        color:black;

        background:white;

        }*/

    #txt{

        height:400px;

        width:600px;

    border:#333 solid 1px;

    padding:5px;}

    p{

    line-height:18px;

    text-indent:2em;}

    </style>

    </head>

    <body>

      <h2 id="con">JavaScript课程</H2>

      <div id="txt"> 

         <h5 id="txt2">JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>

            <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>

            <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>

            <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>

      </div>

      <form>

      <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->

        <input type="button" value="改变颜色" onclick="changecolor()">  

        <input type="button" value="改变宽高" onclick="changewidth()">

        <input type="button" value="隐藏内容" onclick="hidetxt()">

        <input type="button" value="显示内容" onclick="showtxt()">

        <input type="button" value="取消设置" onclick="res()">

      </form>

      <script type="text/javascript">

    function changecolor()

    {

        var str1=document.getElementById("con");

        str1.style.color="red";

        str1.style.background="blue";

    }//定义"改变颜色"的函数



    function changewidth()

    {

        var str2=document.getElementById("txt");

        str2.style.width="400px";

        str2.style.height="300px";

        

    }//定义"改变宽高"的函数



    function hidetxt()

    {

        var str3=document.getElementById("txt2");

        str3.style.display="none";

        

    }//定义"隐藏内容"的函数

    function showtxt()

    {

        var str4=document.getElementById("txt2");

        str4.style.display="block";

        

    }//定义"显示内容"的函数

    function res()

    {

        var str5=confirm("取消设置么?");

        if (str5=true)

        {

            txt2.removeAttribute("style");

            txt.removeAttribute("style");

            con.removeAttribute("style");

        }

        else

        {

            alert("再见!");

        }

    }


    //定义"取消设置"的函数




      </script>

    </body>

    </html>

    我点取消也会重置设置 跟点确定是一样的


  • Keeln
    2016-08-08 11:31:11

    这个问题模棱两可的,没法帮。Show Ur code

  • 陈婉
    2016-08-07 19:47:37

    你最好把你的代码粘贴出来,这样大家方便帮你看看

  • xuhao233551289
    2016-08-07 19:41:58

    是不是你没在input加onclick啊。

  • JOKER0727
    2016-08-07 18:34:49

    不会吧!!

JavaScript入门篇

JavaScript做为一名Web工程师的必备技术,本教程让您快速入门

741129 学习 · 9865 问题

查看课程

相似问题