【问题标题】:Refresh button using image in JavaScript使用 JavaScript 中的图像刷新按钮
【发布时间】:2013-02-23 15:28:45
【问题描述】:

我正在尝试使用图像 (.jpg) 在 JavaScript 中为一个网站制作一个刷新按钮,每次它刷新两个图像时都会发生变化(从数据库上传),但由于某种原因它不会工作。到目前为止,这是我的代码:

<div align="center">
<SCRIPT LANGUAGE="JavaScript">
var body = document.getElementsByTagName("body")[0];
var s = document.createElement("input");
s.src = "/Volumes/playground_people/s1267664/html/dwd/buttons/next_btn.jpg";
s.type = "image";
body.appendChild(s);

document.write('<form><input type=button value="Next" onClick="history.go()"></form>')
</script>
</div>

【问题讨论】:

    标签: javascript image button refresh


    【解决方案1】:

    由于我不清楚你真正想要实现什么,我只能猜测什么可以帮助你。

    第一件事是您的“Next”-input 在类型周围缺少一些引号:

    document.write('<form><input type="button" value="Next" onClick="history.go()"></form>');
    

    我建议您将form 直接放入div-container,而不是使用document.write

    您是否尝试将脚本中的图像添加到您在下面定义的button 中? 然后你必须参考它,例如id:

    <div align="center">
        <input type="button" id="nextBtn" value="Next" onClick="location.reload(true)">
        <script language="JavaScript">
            var b = document.getElementById("nextBtn");
            b.src = "/Volumes/playground_people/s1267664/html/dwd/buttons/next_btn.jpg";
            b.type = "image";
        </script>
    </div>
    

    我还删除了form,因为它将图像坐标发送到重新加载的页面,并使用location.reload而不是history.go()

    此代码将图像添加到按钮,单击时刷新页面。

    【讨论】:

    • 感谢您的帮助!我是 Java n00b(我是所有代码相关的 n00b tbh)。供将来参考:这是我使用的有效代码:
    • 没问题 ;) 实际上你的最终解决方案更简单:D
    猜你喜欢
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    相关资源
    最近更新 更多