Juery添加删除div或span问题
2012-08-15 18:00 C#与.NET探索者 阅读(247) 评论(0) 编辑 收藏 举报pageload和每次的触发事件都得bind事件Listener
<%@ Page Language="C#"
AutoEventWireup="true" CodeFile="bind事件.aspx.cs" Inherits="bind事件"
%>
<!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
runat="server">
<title></title>
<script
src="include/jquery-1.6.2.min.js"
type="text/javascript"></script>
<script
language="javascript" type="text/javascript">
$(function ()
{
bindlister();
$(".yushe
span").click(function () {
$(".bbb").append("<span>" +
$(this).text() + "</span>");
bindlister();
});
})
function bindlister()
{
$(".bbb span").unbind().click(function () {
$(this).remove();
});
}
</script>
<style>
.aaa{border:1px solid
#e4e4e4;width:200px;height:50px;background-color:Red;padding:5px;}
.bbb>span{border:1px solid
#green;width:200px;height:50px;background-color:Red;padding:5px;}
</style>
</head>
<body>
<div
class="bbb">
<span class="aaa">内置标签</span>
</div>
<div class="yushe">
<span>A</span><span>B</span><span>C</span>
</div>
<input type="text" name="a" id="a" onblur="checkForm();"
/>
</body>
</html>