各种选择器会用,但是还不熟练

Original 2018-12-17 15:22:31 218
abstract:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>index</title></head><body > <div >     

QQ图片20181217152117.png

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>index</title>
</head>
<body >
 <div >
      <div style="float: right;margin-right: 25px">
          <img src="./img/微信图片.jpg" name="pic" >
      </div>
      <div style="float: right;">
          <form action="" name="register">
                  <input type="text" placeholder="用户名" ><br>
                  <input type="password" placeholder="密码不少于8位" ><br>
                  <button>提交</button>
          </form>
    </div>
 </div>
 <script type="text/javascript">
    //通过class获取元素
    let info= document.getElementsByClassName('info').item(0);
    info.style.backgroundColor='black';
    info.style.width='100%';
    info.style.height='200px';
    //通过name获取元素
    let pic=document.getElementsByName('pic').item(0);
    pic.style.width='200px'
    //通过标签名和name来获取元素
    document.images[0].style.height="200px";
    //通过css选择器来获取元素
    let input=document.querySelectorAll('input');
    for(let i=0;i<input.length;i++){
         input[i].style.marginRight='25px';
         input[i].style.marginTop='15px';
         input[i].style.width='200px';
         input[i].style.height='25px';}
 </script>
</body>
</html>

Correcting teacher:天蓬老师Correction time:2018-12-17 15:25:35
Teacher's summary:好吧, 相信你, 下一次 ,作业会更好

Release Notes

Popular Entries