- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Documenttitle>
- <style>
- *{
- padding: 0;
- margin: 0;
- }
- .box{
- width: 211px;
- height: 101px;
-
- margin: 200px auto;
- border: 2px solid #939090;
- display: flex;
- }
- input{
- height: 100px;
- outline: none;
- border: none;
- text-align: center;
-
-
- }
- button{
- width: 50px;
- height: 50px;
- outline: none;
- font-size: 30px;
-
-
- }
- .bottom{
- display: flex;
- flex-direction: column;
- border: 1px solid #939090;
- }
- style>
- head>
- <body>
- <div class="box">
- <input type="text" value="7">
- <div class="bottom">
- <button>+button>
- <button>-button>
- div>
-
- div>
-
- <script>
- //先获取元素
- const input=document.querySelector('input')
-
- const btn=document.querySelectorAll('button')
- //给加号添加事件
- btn[0].addEventListener('click',function() {
- input.value++
- btn[1].disabled=false
-
- })
- //给减号添加事件
- btn[1].addEventListener('click',function() {
- input.value--
- if(input.value<=1){
- btn[1].disabled=true
- }
- })
-
- script>
- body>
- html>
