首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有可变图像源的网站

具有可变图像源的网站
EN

Stack Overflow用户
提问于 2016-06-28 08:42:52
回答 1查看 35关注 0票数 1

所以,我正在试着做一个网站,在那里我可以有一张每天都在变化的图片。我需要帮助将图像源设置为变量imageurl。另外,使其变量imageurl是全局的。

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

代码语言:javascript
复制
<!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>
EN

回答 1

Stack Overflow用户

发布于 2016-06-28 09:04:48

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

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38065343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档