Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 文本区域在添加或删除内容时自动调整大小_Jquery_Textarea_Autosize - Fatal编程技术网

Jquery 文本区域在添加或删除内容时自动调整大小

Jquery 文本区域在添加或删除内容时自动调整大小,jquery,textarea,autosize,Jquery,Textarea,Autosize,所以我找到了这个代码并遵循它 $(function() { // changes mouse cursor when highlighting loawer right of box $("textarea").mousemove(function(e) { var myPos = $(this).offset(); myPos.bottom = $(this).offset().top + $(this).outerHeight(); myPos.right = $(

所以我找到了这个代码并遵循它

$(function() {
//  changes mouse cursor when highlighting loawer right of box
$("textarea").mousemove(function(e) {
    var myPos = $(this).offset();
    myPos.bottom = $(this).offset().top + $(this).outerHeight();
    myPos.right = $(this).offset().left + $(this).outerWidth();

    if (myPos.bottom > e.pageY && e.pageY > myPos.bottom - 16 && myPos.right > e.pageX && e.pageX > myPos.right - 16) {
        $(this).css({ cursor: "nw-resize" });
    }
    else {
        $(this).css({ cursor: "" });
    }
})
//  the following simple make the textbox "Auto-Expand" as it is typed in
$("textarea").keyup(function(e) {
    //  this if statement checks to see if backspace or delete was pressed, if so, it resets the height of the box so it can be resized properly
    if (e.which == 8 || e.which == 46) {
        $(this).height(parseFloat($(this).css("min-height")) != 0 ? parseFloat($(this).css("min-height")) : parseFloat($(this).css("font-size")));
    }
    //  the following will help the text expand as typing takes place
    while($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
        $(this).height($(this).height()+1);
    };
});
});
$(函数(){
//高亮显示方框右侧时更改鼠标光标
$(“textarea”).mousemove(函数(e){
var myPos=$(this.offset();
myPos.bottom=$(this.offset().top+$(this.outerHeight();
myPos.right=$(此).offset().left+$(此).outerWidth();
如果(myPos.bottom>e.pageY&&e.pageY>myPos.bottom-16&&myPos.right>e.pageX&&e.pageX>myPos.right-16){
$(this.css({cursor:“nw resize”});
}
否则{
$(this.css({cursor:});
}
})
//下面的简单示例使文本框在键入时“自动展开”
$(“文本区域”).keyup(函数(e){
//此if语句检查是否按了backspace或delete,如果是,则重置框的高度,以便可以正确调整其大小
如果(e.which==8 | | e.which==46){
$(this.height)(parseFloat($(this.css(“最小高度”))!=0?parseFloat($(this.css(“最小高度”)):parseFloat($(this.css(“字体大小”));
}
//以下内容有助于文本在键入时展开
while($(this.outerHeight()

它与自动展开功能配合得很好,但它不会在删除文本时使其变小,在删除内容时也不会变小。有人能帮我吗?

我不明白这个问题,我做了一把小提琴,它似乎工作得很好,你的css中可能设置了最小高度。。。提琴手:是的,我想我的问题超出了规范。我是否使用了错误的jquery版本?我正在使用jquery-1.5.1.min.js非常旧的版本尝试升级…实际上我在服务器上使用它,不允许对其进行任何更改或升级。