如何在每页刷新时旋转一行文本?

时间:2021-11-17 07:19:18

Right now, Reddit is down. Every time you go to it, it displays a logo and below it a funny message. Every time you refresh the page it displays a new message.

现在,Reddit已经失败了。每次你去它,它会显示一个标志,在它下面是一个有趣的消息。每次刷新页面时都会显示一条新消息。

如何在每页刷新时旋转一行文本?

How could I write something simple that ~rotates~ (not random) a line of text on the page every refresh?

我怎么能写一些简单的东西〜每次刷新时在页面上旋转〜(不随机)一行文字?

I'm using ASP.NET MVC but if there is a JavaScript solution to this problem that is fine too.

我正在使用ASP.NET MVC但是如果有一个JavaScript解决方案来解决这个问题也很好。

3 个解决方案

#1


This is how you could write it:

这就是你如何写它:

For javascript, simply use the link posted by Andy White and replace the call to Math.floor(7*Math.random()) to a get/set cookie value. You can find ready-to-use javascript functions to read and write cookies on google.

对于javascript,只需使用Andy White发布的链接,并将对Math.floor(7 * Math.random())的调用替换为get / set cookie值。您可以找到随时可用的JavaScript函数来在谷歌上读取和写入cookie。

For asp.net mvc, the code won't differ a lot, you just have to look for functions to easily manipulate cookies as they are built-in.

对于asp.net mvc,代码不会有太大差异,你只需要寻找功能就可以轻松地操作内置的cookie。

#2


Here's an example of how to do it in javascript:

以下是如何在javascript中执行此操作的示例:

http://www.webdevelopersnotes.com/tips/html/random_text_display_using_javascript_1.php3

#3


Load your message into an array or some sort of collection that is accessible by index.

将消息加载到数组或某种可通过索引访问的集合中。

Something like (i did not verify all syntax):

像(我没有验证所有语法)的东西:

string getQuote(){
 //Load collection of lines
  ArrayList quotes = getQuotesData();
  int quoteCount = quotes.Count;

 // Set session or application variable to some number
  int counter;
  if( !Integer.parse( Session("counter"), counter ) ) { counter = 0; }
  if( counter > quoteCount ) { counter = 0; }

  return quotes[counter];
}

Also, I'm sure something similar is possible in javascript.

此外,我确信在javascript中可能有类似的东西。

#1


This is how you could write it:

这就是你如何写它:

For javascript, simply use the link posted by Andy White and replace the call to Math.floor(7*Math.random()) to a get/set cookie value. You can find ready-to-use javascript functions to read and write cookies on google.

对于javascript,只需使用Andy White发布的链接,并将对Math.floor(7 * Math.random())的调用替换为get / set cookie值。您可以找到随时可用的JavaScript函数来在谷歌上读取和写入cookie。

For asp.net mvc, the code won't differ a lot, you just have to look for functions to easily manipulate cookies as they are built-in.

对于asp.net mvc,代码不会有太大差异,你只需要寻找功能就可以轻松地操作内置的cookie。

#2


Here's an example of how to do it in javascript:

以下是如何在javascript中执行此操作的示例:

http://www.webdevelopersnotes.com/tips/html/random_text_display_using_javascript_1.php3

#3


Load your message into an array or some sort of collection that is accessible by index.

将消息加载到数组或某种可通过索引访问的集合中。

Something like (i did not verify all syntax):

像(我没有验证所有语法)的东西:

string getQuote(){
 //Load collection of lines
  ArrayList quotes = getQuotesData();
  int quoteCount = quotes.Count;

 // Set session or application variable to some number
  int counter;
  if( !Integer.parse( Session("counter"), counter ) ) { counter = 0; }
  if( counter > quoteCount ) { counter = 0; }

  return quotes[counter];
}

Also, I'm sure something similar is possible in javascript.

此外,我确信在javascript中可能有类似的东西。