weixin_33695450 2012-10-17 19:11 采纳率: 0%
浏览 43

html文本会覆盖自身

After pasting some plain text as html via ajax (jQuery) into a div, the text overwrites itself.

example

I don't know if it's helpful to post all my code, but maybe someone had faced the same problem before and can give me a hint.

I'm using Symfony2 and jQuery (ajax request to action).

here is the ajax request and callback:

$('.tile').click(function(e){
    e.preventDefault();

    var thisTileImg = e.target
    var x = thisTileImg.x;
    var y = thisTileImg.y;
    var tileID = thisTileImg.id;

    // execute ajax-request to turnAction and give parameters for x and y of the tile
    var request = $.ajax({
      url: pathTurnAction,
      type: "POST",
      data: {'x':x, 'y':y, 'tileID':tileID},
      dataType: "html"
    });

    request.done(function(msg) {
        var obj = jQuery.parseJSON(msg);
        switch(obj.result){
            case -1:
      showPopup(obj.text, obj.button);
                break;
            case 0:
                thisTileImg.src = pathTileImg0;
                break;
            case 1:
                thisTileImg.src = pathTileImg1;
                break;
        }
        $('#attempts_left').html(obj.attempts);
    });

    request.fail(function(jqXHR, textStatus) {
        // TODO: do something with the error
        // ...
        alert( "Request failed: " + textStatus );
    });

});

function showPopup(text, button){
    $('#overlay_popup_text').html(text);
    $('#overlay_popup_button').html(button);
    $('#overlay_bg').show();
    $('#overlay_popup').show().center();
}

and the html/css

<div id="overlay_bg"></div>
<div id="overlay_popup">
  <div id="overlay_popup_text"></div>
  <div id="overlay_popup_button"></div>
</div>

#overlay_bg {
width: 100%;
height: 1900px;
overflow: hidden;
position: absolute;
left: 0;
top: 0;
display: none;
background: rgba(0, 0, 0, 0.75);
-moz-transition: opacity 1.5s;
-o-transition: opacity 1.5s;
-webkit-transition: opacity 1.5s;
z-index: 10000;
}

#overlay_popup {
width: 200px;
height: 200px;
overflow: hidden;
position: absolute;
left: 0;
top: 0;
display: none;
padding: 15px;
background-color: #fff;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
z-index: 10001;
}

#overlay_popup_text {
  height: 80px;
}
#overlay_popup_buttons {
  height: 80px;
}
  • 写回答

1条回答 默认 最新

  • weixin_33721427 2012-11-28 05:33
    关注

    The solution was a CSS related. Line-height was 0. Text just kept writing on top of itself.

    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺