jquery遇到了个问题

xupark 2012-08-15 09:23:24
自定义了一个验证码刷新函数,如下:

//验证码刷新函数
function captchaRefresh()
{
alert( "captchaRefresh" );
$( "#img-captcha" ).src = $( "#img-captcha" ).src +"?random="+ Math.random();
captchaIsTrue = false;

$( "#captcha" ).attr( "value", "" );
$( "#info" ).html( "请输入验证码" );
}


程序里在这两个地方调用了这段验证码刷新函数
此处的调用标记为①

//验证码刷新事件
$( "#img-captcha" ).bind( "click", captchaRefresh );

此处的调用标记为②

//登陆验证-回调函数
function loginCallback( xml )
{
var output = $( xml ).find( "root" ).find( "result" ).text();

if( output == "登陆成功" )
{
location.href = "DrawCaptcha";
}
else
{
$( "#info" ).html( output );
captchaRefresh();
}
}

-------------------------------------------------------------------------------------------------------

①②都调用这段调用验证码刷新函数
都只弹出"captchaRefresh"的对话框,
$( "#img-captcha" ).src = $( "#img-captcha" ).src +"?random="+ Math.random();
这段图片刷新代码不起作用

修改这段代码为:
this.src = this.src +"?random="+ Math.random();
①处可以刷新,②处不能,因为②处调用的this没有给定。

要怎么改才能让两处都能刷新呢?
为什么
$( "#img-captcha" ).src = $( "#img-captcha" ).src +"?random="+ Math.random();
这样写不起作用呢?
本人初学,有很多不懂的地方…
...全文
49 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xupark 2012-08-15
  • 打赏
  • 举报
回复
帖子发重复了,不好意思!

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧