How to do alignment in jQuery (text is not able to display at front of time)

丶灬走出姿态 提交于 2019-12-12 01:15:55

问题


I am doing work with web service actually I am facing a problem that my web service text is not showing up in front of time. I need to show the text in front of time.

I do like that.

<div data-role="content" data-theme="d">
    <div class="container">
        <div id="timeID" class ="left">
        </div>
        <div id="realTimeContents" class = "right realtimeContend_h">
        </div>
        <div class="cursor" style="font-size:23px;">|</div>
    </div>
</div>

function nativePluginResultHandler (result)
{
     var currentTime = new Date()
     var hours = currentTime.getHours()
     var minutes = currentTime.getMinutes()

     if (minutes < 10)
        minutes = "0" + minutes

     $('#timeID').append("<b>" + hours + ":" + minutes + " " + "</b>");
     $('#realTimeContents').prepend('<p>'+result+'</p>');
}

My output look like this..

But I need like that .

6:30 Demo file not found
6:30 .
6:30  it
6:30 ic
6:31 ic
6:31 hi UI 


回答1:


From what I understand you want your output to look like:

6:30 Demo file not fount

But you have two separate divs that you are populating. One you are populating with just the time. The other you are populating with result.

If you need the two together why arn't you appending just that?

$('#timeID').append("<b>" + hours + ":" + minutes + " " + "</b> " + result + "<br/>");

Why have the two separate divs if you want the time and the result on the same line?

Maybe I misunderstood your question.

UPDATE: Since result contains newlines and you want the time next to every new line try this:

var lines = result.split('<br/>');

$.each(lines, function(){
  var text = "<span style='margin-left: 10px;'>" + this + "</span>";
  $('#timeID').append("<b>" + hours + ":" + minutes + " " + "</b> " + text + "<br/>");
});

Please note that this splits on specifically <br/> if the returned result has line breaks that look differently like <br> you will need to change the split.



来源:https://stackoverflow.com/questions/17893302/how-to-do-alignment-in-jquery-text-is-not-able-to-display-at-front-of-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!