jquery遇到了个问题

xupark xupark 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
自定义了一个验证码刷新函数,如下:

//验证码刷新函数
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();
这样写不起作用呢?
本人初学,有很多不懂的地方…
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
xupark
JavaScript 87,984 成员 224,680 内容