日期:2014-05-16  浏览次数:20356 次

为什么要alert才能刷新验证图片
function   reloadPicAuthorityCode(){
        var   imgObj   =   document.getElementById( 'picAuthCodeImg ');   //获得img图片Object
        imgObj.src   =   "http://localhost:8080/test/publish/picAuthCode.do ";
        alert(1);//加此句后能够刷新图片,不加则不行,为什么?
}

-----------这是用到的HTML------------
<tr>
<th   width= "15% "> 验证码 </th>
<td   width= "25% ">
<img   src= "http://localhost:8080/test/publish/picAuthCode.do "   name= "picAuthCodeImg "   align= "absmiddle ">   <input   type= "text "   name= "authorityCode "   size= "4 "   value= " "> <br>
<a   href= "javascript: "   onclick= "reloadPicAuthorityCode() "> 看不清,换一张 </a>
</td>
<td   width= "60% "> 请输入验证图片中的字符 </td>
</tr>


------解决方案--------------------
imgObj.src = "http://localhost:8080/test/publish/picAuthCode.do?r= " + Math.random();
------解决方案--------------------
说明你用的不是IE(个人感觉)
同意上面那位的
------解决方案--------------------
alert(1);//加此句后能够刷新图片,不加则不行,为什么?
这里因为请求到服务器还需要时间,所以不行,可以在下面用setTimeout来执行掩盖这个问题
或者判断他的状态
------解决方案--------------------
弹出一下,可以消除缓存吧。

------解决方案--------------------


后面加math.random()