javascript - 具有可变图像源的网站

标签 javascript html css

所以,我正在尝试制作一个网站,在那里我可以拥有每天都会变化的图片。我需要帮助将图像源设置为变量 imageurl。另外,使变量 imageurl 成为全局变量。

让我澄清一下,我希望它能够将变量 imageurl 设置为由提示设置的链接,然后将图像设置为 imageurl

<!DOCTYPE html>
<html>

<head>
    <div align="center">
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>picture of the day</title>
         <h1>Jere's picture of the day</h1>
        <link href="style.css" rel="stylesheet" type="text/css">
    </div>
</head>

<body>
    <style>
        div {
            background-color: #8000ff;
            color: #ffffff;
            padding: 20px;
        }
    </style>
    <script src="code.js" type="text/javascript" charset="utf-8"></script>

    <script>
        function myFunction() {
            isitjere = prompt("Password?");
            if (isitjere === "thedog")
                alert("password:" + isitjere + " " + "has been accepted");
            editimage = prompt("do you want to change the image?(type yes or no)");
            if (editimage === "yes")
                imageurl = prompt("paste the image url(if you dont have a url for it you can upload it and paste the upload link)");
        }
    </script>
    <button onclick="myFunction()">edit</button>
    <img src=imageurl>
    </div>
</body>
</html>

最佳答案

不知道你的意图是什么..但这里有一个代码片段可以工作:) (http://codepen.io/f7o/pen/VjpjOW)

<head>

</head>

<body>
  <script>
    function myFunction() {
       var isitjere = prompt("Password?");
                if (isitjere === "thedog")
                    alert("password:" + isitjere + " " + "has been accepted");
                var editimage = prompt("do you want to change the image?(type yes or no)");
                if (editimage === "yes")
                    var imageurl = prompt("paste the image url(if you dont have a url for it you can upload it and paste the upload link)");
      console.log(imageurl);
    $("#pic").attr('src',imageurl);
    }
  </script>
  <button onclick="myFunction()">edit</button>

  <div align="center">
    <title>picture of the day</title>
    <h1>Jere's picture of the day</h1>
  </div>
  <img id="pic" src="https://www.google.com/images/nav_logo242.png">

</body>

</html>

关于javascript - 具有可变图像源的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38065343/

相关文章:

php - 在 CSS 中包裹长文本

html - 如何在不影响页面设计的情况下排列div

css - "Domains, protocols and ports must match"错误 + 修复了 Chrome 中的 div 卡住

javascript - JQuery CSS 两个值

css - 如何将 Input 和 Image 元素保持在同一行

javascript - 当 jquery 中的 min > max 时实时验证输入

javascript - ruby 轨道 : Calling controller method from javascript

html - 我想在悬停在汉堡包上时显示文本 "Menu"(字体很棒的图标)

html - 带有固定导航栏的粘性页脚

javascript - 覆盖默认浏览器alert()方法