Jquery动态添加及删除页面节点元素示例代码
废话不多说,直接上代码!
<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title>Jquery动态添加及删除页面节点</title>
<scriptsrc="http://code.jquery.com/jquery-1.8.3.min.js"></script><!--引用jqurey库文件-->
<style>
.container{width:1000px;margin:0auto;}
.top{height:25px;line-height:25px;}
.topselect{width:80px;height:22px;line-height:22px;}
.topinput{width:56px;height:22px;}
.add{line-height:30px;}
li{list-style:none;}
span{cursor:pointer;}
</style>
<script>
$(function(){//页面加载完毕后执行
$("input").click(function(){//添加操作
vargetval=$("select").val();//获取当前选中的select值
$("p").before('<li>'+getval+'<span>X</span></li>');//在p标签前加入所要生成的代码
});
});
$("span").live("click",function(){//通过live()方法附加的事件处理程序适用于匹配选择器的当前及未来的元素(比如由脚本创建的新元素)
$(this).parent().remove();//移除当前点击元素的父元素
});
</script>
</head>
<body>
<div>
<div>
<select>
<option>我是一号</option>
<option>我是二号</option>
<option>我是三号</option>
<option>我是四号</option>
<option>我是五号</option>
</select>
<inputvalue="添加"type="button"/>
</div>
<div><p></p></div>
</div>
</body>
</html>
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下