简体   繁体   English

如何使用jQuery新的高级行情自动收录器从文本文件读取文本?

[英]How do I use jQuery new advanced ticker to read text from text file?

I'm trying this code now in my website: 我正在我的网站上尝试此代码:

<script>
var file = "http://newsxpressmedia.com/files/theme/test.txt";
function getFile(){
    $.get(file,function(txt){
        var lines = txt.responseText.split("\n");
        for (var i = 0, len = lines.length; i < len; i++) {
            save(lines[i]);
          <ul class="newsticker">lines[i]</ul>
        }
    }); 
}
</script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>

<script>
$('.newsticker').newsTicker({
    row_height: 48,
    max_rows: 2,
    speed: 6000,
    direction: 'up',
    duration: 400,
    autostart: 1,
    pauseOnHover: 0
});
</script>

But I don't see anything. 但是我什么也没看到。 The text suppose to scroll up. 文本应该向上滚动。

In the original the code was: 原始代码是:

<ul class="newsticker">
    <li>Etiam imperdiet volutpat libero eu tristique.</li>
    <li>Curabitur porttitor ante eget hendrerit adipiscing.</li>
    <li>Praesent ornare nisl lorem, ut condimentum lectus gravida ut.</li>
    <li>Nunc ultrices tortor eu massa placerat posuere.</li>
</ul>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>

<script>
$('.newsticker').newsTicker({
    row_height: 48,
    max_rows: 2,
    speed: 6000,
    direction: 'up',
    duration: 400,
    autostart: 1,
    pauseOnHover: 0
});
</script>

What am I doing wrong ? 我究竟做错了什么 ? I checked I the file test.txt exist and I can read it but the code : 我检查了文件test.txt是否存在,并且可以读取,但代码如下:

<script>
    var file = "http://newsxpressmedia.com/files/theme/test.txt";
    function getFile(){
        $.get(file,function(txt){
            var lines = txt.responseText.split("\n");
            for (var i = 0, len = lines.length; i < len; i++) {
                save(lines[i]);
              <ul class="newsticker">lines[i]</ul>
            }
        }); 
    }
    </script>

Is not working I don't see anything. 没有工作,我什么也看不到。 Tried to add in the FOR LOOP the line: 试图在FOR LOOP中添加以下行:

<ul class="newsticker">lines[i]</ul>

But I guess it's wrong. 但是我想这是错误的。

EDIT** 编辑**

The code is now look like this: 现在的代码如下所示:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>

<script>
$(function() {
    var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
        var lines = txt.responseText.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>');
        }
        $ul.appendTo('body').newsTicker({
            row_height: 48,
            max_rows: 2,
            speed: 6000,
            direction: 'up',
            duration: 400,
            autostart: 1,
            pauseOnHover: 0
        });
    });
});
</script>

But it does nothing i don't see any text at all. 但是它什么也没做,我根本看不到任何文本。

EDIT** 编辑**

Opend the console dev on my website at: http://newsxpressmedia.com/ And i see this text in the console: 在我的网站上打开控制台开发者: http ://newsxpressmedia.com/,我在控制台中看到以下文本:

6 Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. 6考虑使用“ dppx”单位代替“ dpi”,因为在CSS中,“ dpi”表示每CSS英寸的点数,而不是每物理英寸的点数,因此不对应于屏幕的实际“ dpi” 。 In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), not all, not all, not all, only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) (index):1 Uncaught TypeError: Cannot call method 'split' of undefined (index):101 event.returnValue is deprecated. 在媒体查询表达式中:仅屏幕和(-webkit-min-device-pixel-ratio:2),不是全部,不是全部,不是全部,仅屏幕和(min分辨率:192dpi),仅屏幕和(min分辨率:2dppx)(索引):1未捕获的TypeError:无法调用未定义(索引):101 event的方法'split'.returnValue已弃用。 Please use the standard event.preventDefault() instead. 请改用标准event.preventDefault()。

You have two issues. 你有两个问题。 The first is that you need to create your li elements and append them to the dom. 首先是您需要创建li元素并将其附加到dom。 The second is that you aren't waiting for the ajax call to finish before setting up the newsticker plugin. 第二个是在设置newsticker插件之前,您无需等待ajax调用完成。 I also don't see a reason to have the getFile function: 我也看不到具有getFile函数的原因:

$(function() {
    var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
        var lines = txt.responseText.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>');
        }
        $ul.appendTo('body').newsTicker({
            row_height: 48,
            max_rows: 2,
            speed: 6000,
            direction: 'up',
            duration: 400,
            autostart: 1,
            pauseOnHover: 0
        });
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从文本文件填充 HTML 代码 - Populating HTML Ticker from a Text File 如何阅读本地文本文件? - How do I read a local text file? 如何使用 jQuery 从 JSON 读取文件? - How do I use jQuery to read a file from JSON? 如何使用读取文本文件的代码和在红色框中滚动文本的代码? - How do i use the code that read the text file that was working with the code that scroll the text in the red box? 在 javascript 中,如何使用 fs.writeFile 并循环数组并在新文本文件中垂直打印数组中的每个项目 - In javascript, how do I use fs.writeFile and loop an array and completely print each item from the array vertically in a new text file 如何在jQuery中使用文本链接,同时保留打开新标签页/窗口的点击? - How do I use text link in jQuery while preserving clicks that open to new tabs/windows? 如何使用javascript读取文本文件并将其显示在我的网站上? - How do i use javascript to read a text file and display it on my website? 如何在jQuery中的.text()中显示新行? - How do I display new line in .text() in jQuery? 如何将数据从文本文件读取到变量中,以便可以根据值更改颜色? - How do I read the data from text file into a variable so I can change the color based on the value? 如何从jQuery中文本区域中的路径读取文件 - how to read file from a path which is in text area in jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM