Jquery 操作语句问题,click事件没有被触发。
<formaction="#"><divclass="msg"><divclass="caption"><spanclass="bigger">bigger</span>...
<form action= "#">
<div class="msg">
<div class="caption">
<span class="bigger">bigger</span>
<span class="smaller">smaller</span>
</div>
<div class ="content">
<textarea id="comment" rows = "8" cols="20">this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!</textarea>
</div>
</div>
</form>
<script>
$(function () {
var $comment = $("#comment");
$(".bigger").click(function () {
if ($comment.height() < 500) {
$comment.height($comment.height() + 50);
}
});
$(".smaller").click(function () {
if ($comment.height() > 50) {
$comment.height($comment.height() - 50);
}
});
});
</script> 展开
<div class="msg">
<div class="caption">
<span class="bigger">bigger</span>
<span class="smaller">smaller</span>
</div>
<div class ="content">
<textarea id="comment" rows = "8" cols="20">this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!</textarea>
</div>
</div>
</form>
<script>
$(function () {
var $comment = $("#comment");
$(".bigger").click(function () {
if ($comment.height() < 500) {
$comment.height($comment.height() + 50);
}
});
$(".smaller").click(function () {
if ($comment.height() > 50) {
$comment.height($comment.height() - 50);
}
});
});
</script> 展开
1个回答
展开全部
是不是没有正确引入jquery库?我用你的代码没发现问题啊
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function () {
var $comment = $("#comment");
$(".bigger").click(function () {
if ($comment.height() < 500) {
$comment.height($comment.height() + 50);
}
});
$(".smaller").click(function () {
if ($comment.height() > 50) {
$comment.height($comment.height() - 50);
}
});
});
</script>
</head>
<body>
<form action= "#">
<div class="msg">
<div class="caption">
<span class="bigger">bigger</span>
<span class="smaller">smaller</span>
</div>
<div class ="content">
<textarea id="comment" rows = "8" cols="20">this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!this is a Jquery test!</textarea>
</div>
</div>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询