61,112
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin:0;
padding:0;
}
.box{
margin:30px;
}
.input{
display:inline-block;
}
</style>
</head>
<body>
<div class="box">
<div class="input"></div>
<button class="btn"> + 按钮</button>
</div>
<script src="./js/jquery@2.2.4.js"></script>
<script>
$(function(){
$(".btn").on("click",function(){
let Input=$("<input />");
Input.css({
width:"50px",
height:"10px",
margin:"10px"
});
Input.on("blur",function(){
if(this.value){
let Span=$("<span></span>"),I=$("<i>x</i>");
Span.css({
padding:"0 5px",
background:"#EEF",
color:"#DD8",
margin:"5px",
border:"1px solid #D5F"
})
I.css({
padding:"0 5px",
color:"#ccc",
cursor:"pointer",
fontStyle:"normal"
})
I.on("click",function(){
$(this).parent().remove();
});
Span.text(this.value);
Span.append(I);
$(".input").append(Span)
}
$(this).remove()
$(".btn").show()
});
$(".input").append(Input);
Input.focus()
$(".btn").hide()
})
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin:0;
padding:0;
}
.input{
display:inline-block;
}
</style>
</head>
<body>
<div>
<div class="input"></div>
<button class="btn"> + 按钮</button>
</div>
<script src="./js/jquery@2.2.4.js"></script>
<script>
$(function(){
$(".btn").on("click",function(){
let Input=$("<input />");
Input.css({
width:"50px",
height:"10px",
margin:"10px"
})
Input.on("blur",function(){
if(!this.value){
$(this).remove()
}
$(".btn").show()
});
$(".input").append(Input);
Input.focus()
$(".btn").hide()
})
})
</script>
</body>
</html>