jquery 函数不适用于新闻报道

标签 jquery jquery-plugins news-ticker

我正在页面中的新闻部分使用新闻收报机,并且我想对这些新闻使用 Prettyphoto 插件,但是当 < li > 项目更改其位置时,任何 jquery 函数都不起作用。

例如,当第一项成为最后一项时,所有 jquery 函数都不起作用

这是代码

$(document).ready(function(){
    var first = 0;
    var speed = 1000;
    var pause = 3500;

    function removeFirst(){
       first = $('ul#listticker li:first').html();
       $('ul#listticker li:first')
        .animate({opacity: 0}, speed)
        .fadeOut('slow', function() {$(this).remove();});
       addLast(first);
    }

    function addLast(first){
        last = '<li style="display:none">'+first+'</li>';
        $('ul#listticker').append(last)
        $('ul#listticker li:last')
        .animate({opacity: 1}, speed)
        .fadeIn('slow')
    }

    interval = setInterval(removeFirst, pause);

        //Codes above are for the news ticker

    $(".news").click(function(e){
        e.preventDefault(); //I assign news class to links if there is no image for the news on db but it doesn't even work
    });

    $("#newsdiv a[rel^='gallery']").prettyPhoto({
        theme:'light_rounded'
    });
});

以及 php 函数的 HTML 结果

<ul id="listticker">
    <li>
        <img src="http://example.com/m.../k_haber.png"><a href="#" class="news">12.05.2011</a><span class="news-text">Some Title</span>
    </li>
    <li>
        <img src="http://example.com/../some.png"><a href="http://example.com/../news/p_some.jpg" class="news-title" rel="gallery[dd0]"> 12.05.2011</a><span class="news-text">Some Other Title</span>
    </li>
</ul>

知道可能是什么原因造成的或如何解决它吗?

编辑:
我假设问题是由于 jquery html 选择器而发生的。

最佳答案

在 dom 就绪事件之外获取变量和函数声明。 http://jsfiddle.net/jfahv/

关于jquery 函数不适用于新闻报道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5982386/

相关文章:

javascript - 使用 Jquery/Javascript 访问嵌入在 XML 中的 JSON

jquery - 如何扩展 jQuery 插件?

javascript - jQuery load() 导致 jQuery 插件错误

ajax - 实时股票行情研究 - 使用 Ajax 和 PHP 或 Socket.io 和 Node.js 或者 Flash 或 Ruby on Rails

php - 类似于 php 中的 facebook 的新闻行情

javascript - 正则表达式检查路径是相对的还是绝对的

jquery val() 不显示跨度的值

jQuery 新闻行情指示器 - 无法在我的网站上运行

jquery - Highcharts 未在 Internet Explorer 中呈现