jq实现点击添加和删除一行
2016-07-07 10:58
176 查看
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jq实现点击添加和删除一行</title>
<script src="scripts/jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="line">
<div>
<input type='button' id='add' value='加选项' />
<input type='button' id='minus' value='减选项'/>
</div>
<p><span></span><input type="text" name=""></p>
</div>
$("#add").click(function(){
var num =$("#line").children("p").length+1;
$("#line").append(("<p><span></span><input type="text" name=""></p>"));
});
$("#minus").click(function(){
var length=$("#line").children("p").length;
if(length<2){
alert("至少保留一项");
}else{
$("#line").children("p:last-child").remove();
}
});
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jq实现点击添加和删除一行</title>
<script src="scripts/jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="line">
<div>
<input type='button' id='add' value='加选项' />
<input type='button' id='minus' value='减选项'/>
</div>
<p><span></span><input type="text" name=""></p>
</div>
$("#add").click(function(){
var num =$("#line").children("p").length+1;
$("#line").append(("<p><span></span><input type="text" name=""></p>"));
});
$("#minus").click(function(){
var length=$("#line").children("p").length;
if(length<2){
alert("至少保留一项");
}else{
$("#line").children("p:last-child").remove();
}
});
</body>
相关文章推荐
- Swift基础之UITabBarController(这是在之前UITableView中直接添加的)
- Cocos开发VR菜鸟宝典 第八讲:为GearVR开发一款深海捕鱼VR游戏
- 设计流程图工具
- Entity Framework Tutorial Basics(37):Lazy Loading
- 页面输出小数为两位的数字
- 基于R-CNN的物体检测
- Android几种加载网络图片的方式(附带源码Demo)
- Handler的应用---探讨android更新UI的几种方法
- 数据加载、存储与文件格式
- 调整数组顺序使奇数位于偶数前面
- js中的json使用
- redis限制单ip、单用户的访问次数
- LeetCode—SameTree
- Reverse Words in a String II
- windows的139端口和445端口的区别
- MySQL之索引优化
- spark standalone
- 前端——使footer永远在网页底部的方法
- yii-验证码
- jquery中正则表达式的书写