0

分区:

<div id="hilo" style="width:48%;height:380px;overflow:auto;float:right;">

Javascript:

$('#re').click(function() {
    var error = 0;
    if($("#texto").val() == ""){
        $("#texto").css("border","solid 1px #990000");
        error = 1;
    }
    if(error == 1){
        return false;
    } else {
        var texto = $("#texto").val();
        var conv = $(this).attr("name");
        $.ajax({
            type: "POST",
            url: "ajaxHilo.php",
            cache: false,
            data: {
                'texto' : texto,
                'conv_id' : conv,
                'regresar' : 'ultimo'
            },
            success: function(data,status){
                $("#hilo").append(data);
                $("#texto").val("");
                var hei = $('#hilo').prop('scrollHeight');
                alert(hei);
                $("#hilo").animate({ scrollTop: hei}, 500);
                return false;
            },
            error: cualquierError
        });
    }
   });

id = re 的元素是一个按钮。

对于溢出的 div 的大小,我得到了最奇怪的结果,脚本将一个新的 div 插入到 div hilos 中,每次只有两行新内容,每行不超过 30 或 40 像素,但是,计数从 1473 开始,并且然后跳转到 2193 然后 2913 等等......

Firefox 滚动到底部,但 IE 给了我不同的数字(较小的数字)并且根本不滚动到底部......

我希望不要太混乱......

4

1 回答 1

0

我会在名为“hilo_content”的“hilo”中添加一个 div,将来自 ajax 响应的数据附加到它,然后使用 .outerHeight() 获取高度值。所以是这样的:

<div id="hilo" style="width:48%;height:380px;overflow:auto;float:right;">
    <div id="hilo_content"></div>
</div>

并在成功回调中:

success: function(data,status){
    $("#hilo_content").append(data);
    $("#texto").val("");
    var hei = $('#hilo_content').outerHeight();
    alert(hei);
    $("#hilo_content").animate({ scrollTop: hei}, 500);
    return false;
}
于 2012-11-15T11:38:45.300 回答