简体   繁体   English

如何在 HTML 中使用 jQuery 添加多个字符串

[英]How to add multiple strings with jQuery in HTML

First of all, I apologize if the question is too primal for this Q&A site.首先,如果这个问题对于这个问答网站来说过于原始,我深表歉意。 I am learning jQuery, and I need to create a countdown sort of display in which, instead of numbers, there will be strings.我正在学习 jQuery,我需要创建一种倒计时显示,其中将显示字符串而不是数字。 Like providing an array in jQuery and setting a div's innerHTML to the string, and changing its class.就像在 jQuery 中提供一个数组并将 div 的innerHTML设置为字符串,并更改其类。

Do you need like the below code.你需要像下面的代码。

 $(function () { count = 0; wordsArray = ["Hi", "How are you", "do you like this", "sample"]; setInterval(function () { count++; $("#word").fadeOut(400, function () { $(this).text(wordsArray[count % wordsArray.length]).fadeIn(400); }); }, 2000); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div id="word">Hello</div>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM