当前位置:网站首页>js写一个搜索添加记录,点击记录删除内容
js写一个搜索添加记录,点击记录删除内容
2022-08-08 21:04:00 【驻风丶】
大概内容如下图,输入框输入内容,点击搜索清空输入框并且在下面生成一个有搜索内容的标签,点击下面的标签则清除此标签
css
<style> *{
margin:0;padding:0;} #one{
width:200px;height:50px;border:1px solid;font-size:18px;} #two{
width:50px;height:50px;border:1px solid;cursor:pointer;} </style>
html
<div class="box">
<input type="text" id="one"/>
<input type="button" id="two" value="搜索"/>
<br><br><hr/><br>
</div>
js
<script type="text/javascript"> //获取元素 //设置按钮事件获取文本内容 //内容传入另一个标签并显示 //设置标签的取消操作 //获取元素 var box = document.getElementsByClassName('box')[0]; var text = document.getElementById('one'); var but = document.getElementById('two'); var res; //设置按钮点击事件 but.onclick = function(){
// console.log(text.value); if(text.value){
// console.log('有'); //创建一个为span的res res = document.createElement('span'); // console.log(res); //设置res的css效果 res.style.border = '1px solid black'; res.style.margin = '10px'; res.style.cursor = 'pointer'; //将文本内容传入res res.innerHTML = text.value; //给res设置点击事件,点击就取消显示 res.onclick = function(){
box.removeChild(this); }; //在盒子内添加res box.appendChild(res); } text.value = ''; } </script>
边栏推荐
- 第十三届蓝桥杯(Web 应用开发)线上模拟赛【第九题】(知乎首页数据动态化)
- C#实现Everything——数据显示
- The access to the local projects, localhosthost can, local IP can't 】
- GeoServer Getting Started Learning: 06-Publishing Multi-level TIF Map Data
- fastapi-实战-综述
- 文档图像二值化DIB_paper_2(更新中...)
- Bagging、Boosting、Stacking集成学习代码
- 【Excel template download with information】
- rancher坑记录
- window下socket(udp)控制台程序
猜你喜欢
随机推荐
【梦想的声音】
GeoServer入门学习:02-安装部署
H5 移动端调取手机相机或相册
Kotlin parsing String path knowledge
SQL注入之搭建dnslog
编译原理——逆波兰式分析程序(C#)
Getting Started with GeoServer: 04-Publishing Shapfile Map Data
GeoServer入门学习:07-发布多层级TIF地图大图数据
IO操作
复合索引使用
阿里云祝顺民:算力网络架构的新探索
【生活成长】——小白成长历险记
3 MapReduce简单原理
day4——乐优商城项目结构(6个微服务)
swagger中忽略方法里的对象参数
[Oracle's NVL function usage]
GeoServer introductory learning: 05-Multi-level MBTiles specification data release
跨域问题 什么时候出现跨域问题 如何解决跨域问题
ssh 登录connectction reset by peer
Iterative version of preorder traversal, inorder traversal, and postorder traversal of binary tree