<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
var i = 0;
$(document).ready(function(){
$("#btn1").click(
function(){
i++;
$("#div1").append('<input type="text" id="t'+i+'"/>');
}
);
$("#btn2").click(
function(){
if(i>0){
$("#t"+i).remove();
i--;
}
}
);
}
);
</script>
<title>无标题文档</title>
</head>
<body>
<input type="button" id="btn1"/> <input type="button" id="btn2"/>
<div id="div1">
<input type="text" id="t0"/>
</div>
</body>
</html>
jQuery添加和删除元素
最新推荐文章于 2021-03-11 10:56:40 发布