当前位置:网站首页>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>
边栏推荐
猜你喜欢
随机推荐
MySQL
新规划|广州都市圈将以广佛为核心,广佛将有18条地铁相连通
一、Canvas应用的背景(个人理解)及基础语法
Bagging、Boosting、Stacking集成学习代码
昇腾Ascend 随记 —— 昇腾 AI 的基本架构
EasyExcel上传文件并使用Postman测试
[MEF]第05篇 MEF的目录(Catalog)筛选
WebView的使用
Centos安装Redis --使用wget
澳洲ABM创新模式将销售代理权给到个体,让利消费者
fashion CNNs code
Iterative version of preorder traversal, inorder traversal, and postorder traversal of binary tree
C语言打印杨辉三角
numpy
目标检测论文 Few-Shot Object Detection with Attention-RPN and Multi-Relation Detector
小程序——切割字符串
并发和并行——从线程,线程池到任务
[Oracle's NVL function usage]
The access to the local projects, localhosthost can, local IP can't 】
最简单的idea构建微服务模块