登风 2015-07-28 03:28 采纳率: 100%
浏览 1612

JQuery事件添加小问题

代码如下:

 <!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>改变文本框大小</title>
<style type="text/css">
*{margin:0px;padding:0px;}
form{margin:40px 40px;border:1px solid #666;width:600px;}
.msg{margin:10px 10px;}
.changeBtn button{margin-left:8px;margin-bottom:8px;}
.comment{width:300px;height:170px;}
</style>
<script src="scripts/jquery-2.0.3源码.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var $comment=$(".comment");
            $(".smalle").click(function(){
                if($comment.height()>50){
                        $comment.height($comment.height()-50);
                    }
                });
            $(".big").click(function(){
                  if($comment.height()<500){
                     $comment.height($comment.height()+50);
                     }
                });

        });
</script>
</head>

<body>
<form>
    <div class="msg">
        <div class="changeBtn">
            <button class="smalle">缩小</button>
            <button class="big">放大</button>
        </div>
        <div >
            <textarea class="comment" >这里是我要评论的内容 </textarea>
        </div>
    </div>
</form>
</body>
</html>

为什么点击之后改变大小瞬间又被弹回原来的大小呢,求教!

  • 写回答

5条回答 默认 最新

  • threenewbee 2015-07-28 03:38
    关注

    var $comment=$(".comment");
    这个写到两个独立的函数中

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记