img src没有在firefox

时间:2018-06-07 09:38:36

标签: javascript html image src

我遇到了问题,我创建了一个验证码,我实现了一个按钮来更改当前版本,它在Google Chrome中运行良好,但在Firefox中不起作用(V. 57.0 32位)

以下是代码:

<head>
    <title>Captcha</title>
</head>

<style> 
  //Style
</style>
<script>

    function refresh(){
        document.getElementById("risp").value = "";
        document.CaptchaImg.src="captcha.php";
    }

</script>
<body style="background-image: url('pattern_17.png');">
<center>
    <div id="div_captcha">
            <h1 style="Font-Family:Impact">CAPTCHA</h1>
            <h3 style="Font-Family:Impact">Sei un robot?</h3><br />
                <form  method="post" id="form" name="form">
                    <div style="background-image: url('pattern_17.png');">
                        <div style="float:left;padding-left:10%;"> 
                            <img src="captcha.php" id="CaptchaImg" name="CaptchaImg"/><br /><br />        
                        </div>
                        <div style="float:right;padding-right:10%;">
                            <input class="myButton" type="button" value="Nuovo captcha" onclick="refresh();" /><br /><br />
                            <input class="myButton" type="reset" value="Reset"/><br /><br /><br />
                            <input type="text" name="risp" id="risp" value="" required maxlength="5" />
                            <input class="myButton" type="submit" value="invia" name="invia" style="width:80px"/>
                        </div>
                     </div>
                </form>
            </div>
        </center>
</body>

提前致谢!

1 个答案:

答案 0 :(得分:0)

img不需要名称,只需要 id

img 元素已弃用name属性!

尝试

document.getElementById("risp").value = "";
document.getElementById("CaptchaImg").src = "captcha.php";