【发布时间】:2022-12-15 07:33:04
【问题描述】:
这是学习 Web 开发基础知识的另一种尝试。
我创建了一个简单的搜索栏。
我想做的是: 如果我们在提供的文本框中输入任何内容,然后我按搜索按钮或回车键, t 在谷歌上搜索提供的文本。
我想知道我们如何使用 JS 编写代码
let textInput=document.querySelector('.textInput');
let searchBtn=document.querySelector('.searchBtn');
searchBtn.addEventListener('click',()=>{
});
searchBtn.addEventListener("keydown", (e)=> {
if (e.key === "Enter") {
}
});
body{
display: grid;
place-items:center;
height: 100vh;
align-content: center;
justify-content: center;
}
.textInput input{
width: 300px;
height: 30px;
}
h3 {
margin-bottom: 10px;
}
.searchBar{
display: flex;
align-items: center;
}
.searchBtn{
width: 50px;
height: 36px;
background-color: rgb(192, 192, 192);
display: grid;
place-items: center;
cursor: pointer;
}
.searchBtn img{
width: 30px;
height: auto;
cursor: pointer;
}
<!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">
<link rel="stylesheet" href="styleSheet.css">
<title>Document</title>
</head>
<body>
<div class="title"><h3> HELLO SEARCH</h3></div>
<div class="searchBar">
<div class="textInput">
<input type="text" placeholder="Search Enything">
</div>
<div class="searchBtn"><img src="https://img.icons8.com/ios-glyphs/60/000000/search--v1.png"/></div>
</div>
<script src="app..js"></script>
</body>
</html>
谢谢你!
【问题讨论】:
标签: javascript html css