5

我试图检测用户何时调整可调整大小的文本区域..

我正在尝试使用此代码执行此操作,但它不起作用:

$('textarea.note').bind("resize", function(){

  alert("resize!!!!!");


})

我真的不想使用任何类型的计时器和循环..帮助!?

4

1 回答 1

10

演示

$(document).ready(function () {
    var $textareas = jQuery('textarea');

    // set init (default) state   
    $textareas.data('x', $textareas.outerWidth());
    $textareas.data('y', $textareas.outerHeight());

    $textareas.mouseup(function () {

        var $this = $(this);

        if ($this.outerWidth() != $this.data('x') || $this.outerHeight() != $this.data('y')) {
            alert($this.outerWidth() + ' - ' + $this.data('x') + '\n' + $this.outerHeight() + ' - ' + $this.data('y'));
        }

        // set new height/width
        $this.data('x', $this.outerWidth());
        $this.data('y', $this.outerHeight());
    });
});
于 2013-08-23T01:13:38.923 回答