gpt4 book ai didi

javascript - 我如何检查行是否为空然后不显示它?

转载 作者:行者123 更新时间:2023-11-29 22:01:33 26 4
gpt4 key购买 nike

这是我在我的 javascript 中用来从文本文件中读取行并将它们添加到 jquery 插件 newsticker 的部分:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://risq.github.io/jquery-advanced-news-ticker/assets/js/jquery.newsTicker.js"></script>
<style>
.newsticker {
max-width: 620px;
margin: auto;
}

.newsticker li {
color: #4e4e4e;
background: #F2F2F2;
overflow: hidden;
height: 28px;
padding: 10px;
line-height: 30px;
list-style: none;
font-size: 20px;
text-align: left;
border-bottom: 1px dotted #2c8162;
}

.newsticker li:hover {
background: #FFF;
}
</style>
<script>
$('body').find('.newsticker').remove();//It will clear old data if its present
var file = "http://newsxpressmedia.com/files/theme/test.txt";
$.get(file, function (txt) {
//var lines = txt.responseText.split("\n");
var lines = txt.split("\n");
$ul = $('<ul class="newsticker" />');
for (var i = 0, len = lines.length; i < len; i++) {
//save(lines[i]); // not sure what this does
$ul.append('<li>' + lines[i] + '</li>'); //here
}
//$ul.appendTo('body').newsTicker({
$ul.appendTo('div.wcustomhtml').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 1000,
autostart: 1,
pauseOnHover: 1
});
});
</script>

例如文本文件中的内容格式是这样的:

Hello everyone5/3/2014Hi world5/3/2013This is a test6/3/2012

I want each time to dislay two lines in the plugin jquery for exmaple this is two lines:

Hi world5/3/2013

Then after this two lines there is empty lines space so dont display it. Then the next two lines.So in the plugin jquery newsTicker i should see the text scrolling like this:

Hello everyone5/3/2014Hi world5/3/2013This is a test6/3/2012

Each time two lines without the space/empty lines. In general it's working but it also show the empty/space lines too.

EDIT**

This is the text file content how it look like:

http://textuploader.com/rl0v

文本是希伯来文,但例如这是两行:

דיווח:ראמי מחלוף,מבכיוממשטוששל אסד,עזב עם משפחתו את סוריה.מבזקים.דווח במק한 בתאריך: 2014 年 4 月 7 日

然后是空行,然后是另外两行。这两行我想每次都在 jquery newsticker 中显示,并将它们作为两行的一个 block 向上滚动。

最佳答案

如何改变 for 循环的行的步骤:

   $('body').find('.newsticker').remove();//It will clear old data if its present 
var file = "http://newsxpressmedia.com/files/theme/test.txt";
$.get(file, function (txt) {
//var lines = txt.responseText.split("\n");
var lines = txt.split("\n");
$ul = $('<ul class="newsticker" />');
for (var i = 0, len = lines.length; i < len; i+=3) { // step: 3
//save(lines[i]); // not sure what this does
$ul.append('<li>' + lines[i] + '</li>'); //here
$ul.append('<li>' + lines[i+1] + '</li>');
}
//$ul.appendTo('body').newsTicker({
$ul.appendTo('div.wcustomhtml').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 1000,
autostart: 1,
pauseOnHover: 1
});
});

关于javascript - 我如何检查行是否为空然后不显示它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23449569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com