jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – html文本覆盖自己大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
将一些纯文本作为html通过ajax(jQuery)粘贴到div中后,文本会覆盖自己.

我不知道发布我的所有代码是否有帮助,但也许有人之前遇到过同样的问题,可以给我一个提示.

我正在使用Symfony2和jQuery(ajax请求操作).

这是ajax请求和回调:

$('.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();
}

和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.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;
}

解决方法

解决方案是CSS相关的.行高为0.文本只是自己写在上面.

大佬总结

以上是大佬教程为你收集整理的jquery – html文本覆盖自己全部内容,希望文章能够帮你解决jquery – html文本覆盖自己所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。