웹 공부/javascript

코딩 스터디(모각코) 12일차 - 한 입 웹개발(JS)

윈터가든 2021. 7. 28. 23:20

오늘의 문제 : 오늘 배운 style 변경 능력을 통해 다양한 디자인 적용하기

 

👉 예시

✅ 오늘의 문제 풀이 인증

<HTML>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>javascript1</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Gamja+Flower&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="./12.css">
    <script src="./12.js"></script>

</head>

<body>
    <div class="box">
        <a id="a">냐앙~</a>
    </div>

    <img src="img/고양이.jpg" alt="" >
    <input type="text" id="text_box">
    <button onclick="btn_click()">시키기</button>
    

</body>

</html>

<CSS>

*{font-family: 'Gamja Flower', cursive;}
.box{
    text-align: center;
    line-height: 200px;
    width: 500px;
    height: 200px;
    border-style: solid; 
    border-color: rgb(126, 91, 66);
    border-width:4px;
    border-radius: 5px;
    margin-bottom: 30px;
    margin-left: auto;
    margin-right: auto;
    font-size: 30px;
    position: relative;
   
}

img{
    display: block;
    width: 300px;
    margin-bottom: 30px;
    margin-left: auto;
    margin-right: auto;
    position: relative;

}

input[type=text]{
   
    display: block;
    border: 3px solid peru;
    border-radius: 5px;
    height: 30px;
    width: 300px;
    font-size: 12pt;
    text-align: center;
    box-sizing: border-box;
    margin-bottom: 20px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    
   
    
}
button{
    display: block;
    margin-right: auto;
    margin-left: auto;
    background-color: navajowhite;
    border: none;
    border-radius: 30px;
    width: 200px;
    height: 50px;
    font-size: 30px;
    color: white;




}
#all{
    background-color:rgba(0, 0, 0, 0.5);
    width: 100%;
 }

<javascript>

function btn_click(){
    var text=document.getElementById('text_box').value;
    

    if(text=="안녕"){
       document.getElementById('a').innerHTML='안녕🐾';
    }
    else if(text=="반가워"){
        document.getElementById('a').innerHTML='반갑다냥😺';
        
    }
    else if(text=="뭐해?"){
        document.getElementById('a').innerHTML='밥 먹는다냥🍖';
        
    }
    else if(text=="불 꺼줘"){
        document.body.style.backgroundColor = '#606060'
        document.getElementById('a').innerHTML='불을 꺼주겠다냥';
        
        
    }
    else if(text== "불 켜줘"){
        document.body.style.backgroundColor = '#ffffff'
        document.getElementById('a').innerHTML='불을 켜주겠다냥';

    }
    else if(text=="오늘 날씨 알려줘"){
       
        document.getElementById('a').innerHTML='<a href="https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=%EC%98%A4%EB%8A%98%EC%9D%98+%EB%82%A0%EC%94%A8&oquery=%EC%97%90%EC%96%B4%ED%8C%9F+as%EC%84%BC%ED%84%B0&tqi=hdZfnsp0YihssbVid0Zssssss10-181247">클릭해라냥</a>'
        
        
    }
  
}

<결과화면>

 

✅ 오늘의 한마디

 

javascript에서 body 전체 css 적용하기

➡ document.body.style.스타일요소