开发者

Stupid Simple Syntax Error

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜