问答详情
源自:3-6 控制类名(className 属性)

求点更改外观后怎么还是one。不应该是two吗

<!DOCTYPE HTML>

<html>

<head>

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

<title>className属性</title>

<style>

  .one{background:yellow; color:red;}

  .two{background:pink; color:green;}

  

</style>

</head>

<body>

<p Id="ggg" class="one">再看看能不能成功</p>

   <form> <input type="button" value="更改外观" onclick="bbb()"/>

</form>

<script type="text/javascript">

 var mg=document.getElementById("ggg");

      document.write(mg.className);

      function bbb(){mg.className="two";

          

      }

 

</script>

</body>

</html>


提问者:慕粉1847419605 2016-12-20 20:56

个回答

  • qq_心守那份爱FORVEVR_03779195
    2016-12-20 21:11:15
    已采纳

    谁让你   家  的    I   大写的。

  • 慕粉1847419605
    2016-12-20 21:43:15


    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>className属性</title>

    <style>

    input{font-size:10px;}

    .one{width:200px; background-color:#FCC;}

    .two{font-size:18px;color:#F00;}

    </style>

    </head>

    <body>

    <p id="con" class="one">再看看能不能成功</p>

       <form> <input type="button" value="更改外观" onclick="modifyclass()"/>

    </form>

    <script type="text/javascript">

    var mychar=document.getElementById('con');

    document.write(mychar.className);

    function modifyclass()

    {mychar.className="two"}

    </script>

    </body>

    </html>


  • 慕粉1847419605
    2016-12-20 21:21:35

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>className属性</title>

    <style>

      .one{background:yellow; color:red;}

      .two{background:pink; color:green;}

      

    </style>

    </head>

    <body>

    <p id="ggg" class="one">再看看能不能成功</p>

       <form> <input type="button" value="更改外观" onclick="bbb()"/>

    </form>

    <script type="text/javascript">

     var mg=document.getElementByid("ggg");

          document.write(mg.className);

          function bbb(){mg.className="two";

              

          }

     

    </script>

    </body>

    </html>


  • 慕粉1847419605
    2016-12-20 21:19:55

    求点更改外观后怎么还是one。不应该是two吗

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>className属性</title>

    <style>

      .one{background:yellow; color:red;}

      .two{background:pink; color:green;}

      

    </style>

    </head>

    <body>

    <p id="ggg" class="one">再看看能不能成功</p>

       <form> <input type="button" value="更改外观" onclick="bbb()"/>

    </form>

    <script type="text/javascript">

     var mg=document.getElementById("ggg");

          document.write(mg.className);

          function bbb(){mg.className="two";  

          }

     

    </script>

    </body>

    </html>

    还是不行呀