我有一个项目即将到期,我需要制作一个以某种方式使用 Javascript 的程序,我决定制作一个页面,当用户输入 1 - 5 之间的数字时显示随机事实;每个数字都有自己的一组事实,并且只会显示这些事实(当用户输入 1 时,不会显示有关 2 的事实)。我可以用 JS 完成这一切,但我更愿意使用 HTML 和 CSS,因为这是我习惯的。我的问题是不知道如何让 JS 功能与 HTML 中的外部 JS 文件一起使用。例如,下面是 HTML 代码块,当用户输入数字 1 时显示一组事实
<p>The FIRST music video on MTV was for the song "Video Killed the Radio Star", by the English new wave group The Buggles, and premiered on August 1, 1981 at 12:01 AM</p>
<p>The FIRST McDonald's restauarant opened in San Bernardino, CA, on May 15, 1940</p>
<p>The FIRST ever mobile phone call was made on April 3, 1973, by Martin Cooper, a senior engineer at Motorola</p>
<p>The FIRST photo of lightning was taken on September 2, 1882, by William Jennings, who wanted to know if lightning really had a zigzag form</p>
<p>The FIRST person to ever go down Niagara Falls in a barrel was 63-year-old Annie Edison Taylor, who was a widowed teacher. She made no money from her stunt</p>
<p>The FIRST Apple computer, developed and designed by Steve Wozniak and presented by Steve Jobs, was released on April 11, 1976</p>
<br /><br />
在 JS 中,我可以这样做,并且效果很好(2-5 的模式相同)
enterNumber = prompt("Enter any number between from 1-5");
enterNumber = parseInt(enterNumber);
}
我基本上想做的是让所有 JS 功能(提示、if else 等)与我的 HTML 和 CSS 文件一起工作,不幸的是,我不知道如何正确设置所有这些。在这种情况下,我如何才能拥有一个工作页面,其中 JS 函数仍然可以与我在 HTML 和 CSS 中使用的功能一起工作?
弑天下
相关分类