当前位置:网站首页>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>
边栏推荐
猜你喜欢

- project experience 】 【 conservation projects

C#实现Everything——UI与查询 附源码
GeoServer Getting Started Learning: 06-Publishing Multi-level TIF Map Data

新规划|广州都市圈将以广佛为核心,广佛将有18条地铁相连通

微信小程序下拉刷新上拉加载更多

Centos安装Redis --使用wget

神经网络论文Enhancing deep neural networks via multiple kernel learning
Getting Started with GeoServer: 04-Publishing Shapfile Map Data

【idea_取消自动import .*】

4 Gephi
随机推荐
Redis Bloom Filter
SQL-堆叠注入(含例题)
Members that must be initialized for initial column initialization
Non-resolvableparent POM for xxxx: Could not find artifact xxx and ‘parent.relativePath‘ points at
Jmeter常见问题处理及常用功能
【线性代数04】投影矩阵P和标准正交矩阵Q
Getting Started with GeoServer: 04-Publishing Shapfile Map Data
【带信息的Excel模板下载】
Solve the problem of slow speed of gradle import package
rancher -部署
必须初始列初始化的成员
[MEF] Chapter 04 MEF's Multi-Component Import (ImportMany) and Directory Services
单片机——DHT11 温湿度传感器
编译原理——LR(1)分析程序(C#)
Kotlin parsing String path knowledge
比较器? 如何使用比较器? 如何自定义比较器?
Fastdata极数:元宇宙报告2022——Hello Metaverse
Flask 教程 第十二章:日期和时间
文档图像二值化DIB_paper_2(更新中...)
- project experience 】 【 conservation projects