鍍金池/ 問答/Java  PHP  Python  HTML/ <textarea>上下拉伸高度后,頁面刷新,怎么保存拉伸后的高度

<textarea>上下拉伸高度后,頁面刷新,怎么保存拉伸后的高度

如圖

<textarea>上下拉伸高度后,頁面刷新,怎么保存拉伸后的高度,

clipboard.png

回答
編輯回答
扯不斷

演示程序地址-三十客

$(document).ready(function () {
    var $texta = $('#my-textarea');
    var lastWidth = localStorage.getItem("my-area-width");
    var lastHeight = localStorage.getItem("my-area-height");
    if(lastWidth && lastHeight) {
        $texta.css("width",lastWidth+"px");
        $texta.css("height",lastHeight+"px");
    }
    $texta.data('x', $texta.outerWidth());
    $texta.data('y', $texta.outerHeight());
    $texta.mouseup(function () {
        var $this = $(this);
        var width = $this.outerWidth();
        var height = $this.outerHeight();
        if (width != $this.data('x') || height != $this.data('y')) {
            alert(width + ' - ' + $this.data('x') + '\n' + height + ' - ' + $this.data('y'));
            localStorage.setItem("my-area-width",width);
            localStorage.setItem("my-area-height",height);
        }
        $this.data('x', width);
        $this.data('y', height);
    });
});
2017年7月4日 15:48
編輯回答
逗婦乳

js獲取寬高 存在本地

2017年4月1日 03:16
編輯回答
笑忘初

利用sessionStorage
保存一下。

2017年9月6日 12:45
編輯回答
不討囍

在sessionStorage存一下

2017年4月6日 05:31