基本上我到目前为止是一个有两个弹出/警报框的页面。第一个要求用户输入他们最喜欢的网站的名称。第二个要求用户输入他们最喜欢的网站的 URL。结果应该显示在主页上的超链接中,作为用户输入的名称,该名称指向他们在单击时输入的 URL。这是我的代码的样子:
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
var favoriteSite;
favoriteSite = prompt ("What is your favorite web site?")
favoriteSite = prompt ("What is the URL of that site?")
document.write('<a href="' + favoriteSite + '"></a>')
</script>
<h1>Link to favorite site.</h1>
<h2>This is my favorite web site</h2>
</body>
</html>
PS。我是 JavaScript 的初学者,任何帮助将不胜感激。谢谢。
这就是我最终改为:
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
var favoriteSite;
var favoriteSiteName;
favoriteSiteName = prompt ("What is your favorite web site?");
favoriteSite = prompt ("What is the URL of that site?");
document.write("<h1>Link to favorite website.</h1>");
document.write("<h2>This is my favorite web site" +" " + favoriteSiteName.link("https://" + favoriteSite + "") + "</p>");
</script>
</body>
</html>