jQuery1.7之后,live就不能用了,改为用on ,但是具体怎么用呢,二话不说,直接放代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<script src="jquery.js"></script>
</head>
<style>
#txt{
width: 800px;
height:100px;
resize: none;
padding:15px;
font-size: 20px;
}
h1{
margin-left: 15px;
}
.comment{
padding: 0px;
border: 3px solid #aaa;
border-radius: 10px;
position: relative;
}
.close{
width: 30px;
height: 30px;
text-align: center;
line-height: 30px;
cursor: pointer;
position:absolute;
top: 1px;
right: 1px;
}
</style>
<body>
<h1>用户评论:</h1>
<form action="">
<textarea name="" id="txt"></textarea>
<br>
<input type="button" value="评论">
</form>
<hr>
<div class="comment">
<h1>aaaaaaaaaaaaaaaaaa</h1>
<div class="close">×</div>
</div>
<div class="comment">
<h1>bbbbbbbbbbbbbbbbbb</h1>
<div class="close">×</div>
</div>
</body>
<script>
$(document).on("click",".close",function(){
$(this).parent().hide();
});
$(":button").click(function(){
val=$("#txt").val();
str="<div class='comment'>";
str+="<h1>"+val+"</h1>";
str+="<div class='close'>×</div>";
str+="</div>";
$("body").append(str);
$("#txt").val("");
});
</script>
</html>
里面的代码可以直接运行