请问如何用HTML代码表达一个最简单的框,宽度是750 高度可以随着输入的内容自动调节。先谢谢了。

2025-04-14 07:09:47
推荐回答(3个)
回答1:

很简单,写个div的样式,宽度固定,高度自适应就行,代码如下:


    内容自适应

回答2:

用textarea吧,再加上这段js

$.fn.autoTextarea = function (options){  
    var defaults = {  
        maxHeight:null,  
        minHeight:$(this).height(),
    };  
    var opts = $.extend({}, defaults, options);  

    return $(this).each(function (){  
        var _this = $(this);  
        _this.bind('paste cur keydown keyup focus blur', function (){  
            var height, style = this.style;  
            style.height = opts.minHeight + 'px';  
            if(this.scrollHeight > opts.minHeight){  
                if(opts.maxHeight && this.scrollHeight > opts.maxHeight){  
                    height = opts.maxHeight;  
                    style.overflowY = 'scroll';  
                }else{  
                    height = this.scrollHeight;  
                    style.overflowY = 'hidden';  
                }  
                style.height = height + 'px';  
            }  
        });  
    });  
}  
$(function(){
$('textarea').autoTextarea({maxHeight:750});
});

回答3:

文本框?还是普通的div框?

相关问答