开发者

Stupid Simple Syntax Error

开发者 https://www.devze.com 2023-02-14 03:45 出处:网络
Trying to make a textarea expand on focus, and contract back to original size on focus. I keep getting syntax errors. I know this is a basic jQ开发者_如何转开发uery structure, but I can\'t get the par

Trying to make a textarea expand on focus, and contract back to original size on focus. I keep getting syntax errors. I know this is a basic jQ开发者_如何转开发uery structure, but I can't get the part right where focus is removed.

$("textarea").focus(function() {
    $(this).animate({"height": "250px"});
}, function() {
   $(this).animate({"height": "50px"});
});
});


Remove the second }); line.

This code can be rewritten to be slightly easier to understand.

var on = function() {
    $(this).animate({"height": "250px"});
};
var off = function() {
   $(this).animate({"height": "50px"});
};
$("textarea").focus(on, off);

If you remove unnecessary local variables on and off, you'll get the code you had (except the wrong part).

edit
Also, focus method takes only one handler (unlike hover). If you want to execute code when element looses focus, use blur.

0

精彩评论

暂无评论...
验证码 换一张
取 消