首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

为什么要alert才能刷新验证图片解决方法

2012-02-25 
为什么要alert才能刷新验证图片functionreloadPicAuthorityCode(){varimgObjdocument.getElementById( pi

为什么要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()

热点排行