代码之家  ›  专栏  ›  技术社区  ›  ant

多行注释问题jquery

  •  0
  • ant  · 技术社区  · 15 年前

    我正在制作一个图片网站,网站上有一堆图片,在每幅图片下面都有评论图片的可能,并且在评论没有页面加载和评论内容的情况下显示之后,问题是当我有长的评论,这些评论打破了当前行,因为我的评论框css溢出隐藏的。以下是示例:

    这是注释-显示 适当地
    这是评论这是 注释这是注释-这是 显示不正确

    因为它断线了。以下是用于此的jquery代码:

    $.ajax({
        type: "POST",
        url: "<?=base_url()?>imagesform/post_comment",
        data: datas,
        success: function () {
            $("#image-comments-" + image_id).attr("class", "comments");
            $("#image-comments-" + image_id).append("<li id=\"new_append_" + image_id+ "\">" + $("#image").find(".comment").val() + "</li>").children(':last').height($('.comments li:last').height()).hide().slideDown(500, function () {
                var bodyHeight = $('html').height();
                $('.addComment').fadeOut(300, function () {
                    $('html').height(bodyHeight);
                });
            });
            alert($("#image").find(".comment").val());
        }
    
    });
    

    这里 $("#image").find(".comment").val() 输入注释的文本区域的值,当我警告它时,整条多行输入是否存在未正确附加到li的地方,即当我感到困惑时,是否有任何建议为什么只附加输入字符串的一部分?

    2 回复  |  直到 15 年前
        1
  •  2
  •   ant    15 年前

    答案是这样的,高度因为某种原因而扭曲了:

    $("#image-comments-" + image_id).append("<li id=\"new_append_" + image_id+ "\" style=\"height:auto !important;\">"
    

    补充 height:auto !important; 新创建的li的css属性

        2
  •  0
  •   Mathias Bynens    15 年前

    在我看来你想用换行符来替换换行符 <br> 通过HTML显示它们。

    alert($("#image").find(".comment").val().replace('\n', '<br>'));