Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以使用JQuery在这段代码中随机化输出引号吗?_Jquery - Fatal编程技术网

我可以使用JQuery在这段代码中随机化输出引号吗?

我可以使用JQuery在这段代码中随机化输出引号吗?,jquery,Jquery,我想使用JQuery调整一个非随机报价生成器,并随机输出报价。我已经尝试了下面的两个脚本,尽管我都无法使用。我想无序的名单是随机的,每次加载页面。有谁能帮我解决这个问题吗 <script type='text/javascript'> window.onload=function(){ var ul = document.querySelector('.word-container'); for (var i = ul.children.length; i >= 0; i--)

我想使用JQuery调整一个非随机报价生成器,并随机输出报价。我已经尝试了下面的两个脚本,尽管我都无法使用。我想无序的名单是随机的,每次加载页面。有谁能帮我解决这个问题吗

<script type='text/javascript'>
window.onload=function(){
var ul = document.querySelector('.word-container');
for (var i = ul.children.length; i >= 0; i--) {
    ul.appendChild(ul.children[Math.random() * i | 0]);
}
</script>

window.onload=function(){
var ul=document.querySelector(“.word容器”);
对于(var i=ul.children.length;i>=0;i--){
ul.appendChild(ul.childs[Math.random()*i|0]);
}


window.onload=function(){
var ul=document.querySelector(“.word容器”),
温度=ul克隆节点(真),
i=临时儿童长度+1;
而(i-->0)
临时附加子对象(临时子对象[Math.random()*i|0]);
ul.parentNode.replaceChild(临时,ul);


jQuery响应报价旋转器演示
jQuery(文档).ready(函数($){
$(“#字”).quoteRotator();
});
  • 生活中最重要的事情是学会如何给予爱,并让爱进来
  • 立即支持链接。动画可以是随机的,也可以是HTML中预定义的。下一个报价动画将全部在fadeInDown中。可选单击下一个报价并悬停以暂停幻灯片放映 所 有 的 瞬 间 都 会 淹 没 于 时 间 的 洪 流,就 像 泪 水 消 逝 在 雨 中。 所有这些时刻都将随着时间流逝而消失,就像雨中的泪水
  • 总是做对。这会让一些人满意,让其他人吃惊
  • 进步是人类能动性的产物。事情变得更好是因为我们让它们变得更好。当我们过于舒适,当我们未能承担风险或抓住机遇时,事情就会出错
  • 如果没有黑暗,你就无法拥有一盏灯
  • 你不能对人类失去信心。人类是一片海洋;如果海洋中的几滴是脏的,海洋就不会变脏
  • 当我做好事时,我感觉良好;当我做坏事时,我感觉不好,这就是我的信仰
  • 我花在广告上的钱有一半被浪费了;问题是我不知道是哪一半

这个怎么样

<script>
jQuery(document).ready(function($) {
    $('#words').quoteRotator();

    var $container = $('.word-container'),
        $quotes = $.makeArray($container.children());

    $quotes.sort(function(){ return (Math.random() > .5 ? -1 : 1)  });

    $.each($quotes,function(i,el){
        $container.prepend(el);
    });
});
</script>

jQuery(文档).ready(函数($){
$(“#字”).quoteRotator();
var$container=$('.word container'),
$quotes=$.makeArray($container.children());
$quotes.sort(函数(){return(Math.random()>.5?-1:1)});
$。每个($引号,函数(i,el){
$container.prepend(el);
});
});

根据quote rotator插件的工作方式,您可能必须将
$('#words').quoteRotator();
移动到函数末尾。

可以!可以调用
.empty()
上的
ul
,然后将
li
以无序形式传回。您可以看到一个例子。

非常感谢您的回答,尽管我担心我在代码中插入了错误。我已经用您的代码修改了问题,尽管它不起作用。请您帮我更正语法,我道歉,我对此很陌生。@Terry将答案编辑到代码中不是一个好做法。请将其删除,因为其他人可能会认为我从问题中粘贴了代码。我更新了答案,我相信问题是我编写了
$('.word.container')
,而不是
$('.word container'))
.DJDavid98非常有效。我无法表达我的感激之情。我将问题恢复到原来的形式,并且为了其他人的参考,我确实需要放入$(“#words”).quoteRotator();在函数结束时。再次感谢。@Terry我很高兴能提供帮助。使用选票下方的复选标记将此标记为已接受的答案将很好地表达您的感激之情:)谢谢您的回复John。您的答案也很有效,尽管添加DJDavid98的代码对我来说比较容易,因为我对编码毫无经验。
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="description" content="">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
    <meta name="keywords" content="">
    <meta name="author" content="Your Name">

    <title>jQuery Responsive Quote Rotator Demo</title>

    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/quoterotator.css">
    <link rel="stylesheet" href="css/animate.css">
    <script src="js/jquery.1.9.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.quoterotator.min.js" type="text/javascript"></script>
    <script>
    jQuery(document).ready(function($) {
        $('#words').quoteRotator();
    });
    </script>

</head>

<body>
<div id="wrapper">

    <div id="words">
        <ul class="word-container">
            <li data-author="---  Morrie Schwartz" data-easeout="lightSpeedOut" data-authorlink="http://codecanyon.net/user/sike">The most important thing in life is to learn how to give out love, and to let it come in. </li>
            <li data-link="http://codecanyon.net/user/sike" data-linkword="1" data-author="" data-easeout="fadeOutDown">Support link now. The animation can be in random or pre-defined in the HTML. Next quote animation will be all in fadeInDown. Optional click to next quote and hover to pause the slideshow.</li>
            <li data-author="" data-link="http://codecanyon.net/user/sike/portfolio" data-linkword="all">所 有 的 瞬 间 都 会 淹 没 于 时 间 的 洪 流,就 像 泪 水 消 逝 在 雨 中。 All those moments will be lost in time, like tears in rain.</li>
            <li data-author="Mark Twain (1835 - 1910)" data-easein="fadeInDown">Always do right. This will gratify some people and astonish the rest. </li>
            <li data-author="---  Susan Rice, Stanford University Commencement, 2010" data-easeout="bounceOut">Progress is the product of human agency. Things get better because we make them better. Things go wrong when we get too comfortable, when we fail to take risks or seize opportunities. </li>
            <li data-author="---  Arlo Guthrie (1947 - )" data-easein="bounceIn">You can't have a light without a dark to stick it in. </li>
            <li data-author="---  Mahatma Gandhi (1869 - 1948)" data-easein="lightSpeedIn">You must not lose faith in humanity. Humanity is an ocean; if a few drops of the ocean are dirty, the ocean does not become dirty. </li>
            <li data-author="---  Abraham Lincoln (1809 - 1865), (attributed)">When I do good, I feel good; when I do bad, I feel bad, and that is my religion. </li>
            <li data-author="---  John Wanamaker (1838 - 1922), (attributed)">Half the money I spend on advertising is wasted; the trouble is I don't know which half. </li>
        </ul>
        <div class="quote">
            <blockquote>
              <p class="quote-content"></p>
            </blockquote>
            <cite class="quote-author"></cite>
        </div>
    </div>



</div>
</body>
</html>
<script>
jQuery(document).ready(function($) {
    $('#words').quoteRotator();

    var $container = $('.word-container'),
        $quotes = $.makeArray($container.children());

    $quotes.sort(function(){ return (Math.random() > .5 ? -1 : 1)  });

    $.each($quotes,function(i,el){
        $container.prepend(el);
    });
});
</script>