如何在jQuery中进行对齐(文本无法提前显示) [英] How to do alignment in jQuery (text is not able to display at front of time)

查看:98
本文介绍了如何在jQuery中进行对齐(文本无法提前显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web服务,实际上我遇到一个问题,即我的Web服务文本未及时显示.我需要在时间前面显示文字.

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.

我喜欢那样.

<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..

但是我需要那样.

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

推荐答案

据我了解,您希望输出显示如下:

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

6:30 Demo file not fount

但是您要填充两个单独的div.您只是时间而已.另一个您正在填充结果.

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/>");

如果要在同一行上显示时间和结果,为什么要使用两个单独的div?

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/>");
});

请注意,如果返回的结果的换行符看上去与<br>不同,则此拆分将专门针对<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.

这篇关于如何在jQuery中进行对齐(文本无法提前显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆