【发布时间】:2016-11-28 09:20:07
【问题描述】:
我想将此发送到在图像的 onload 事件中使用 setInterval 调用的函数,但它会引发以下错误:
未捕获的类型错误:无法读取 undefined(...) 的属性“attr”
<img src="image.jpg" id="24" onload="var sel =this;setInterval(function(sel){calllogin(sel)},20000);"
<script>
function calllogin(sel){
var id = sel.attr("id");
console.log('calling calllogin function',id);
}
</script>
我怎样才能通过这个?
【问题讨论】:
-
从
setInterval函数回调参数中删除sel,即setInterval(function(){calllogin(sel)},20000) -
另外,你缺少一个
}来关闭你的函数calllogin -
@Satpal 我删除了它,现在它显示以下错误; Uncaught TypeError: sel.attr is not a function(...)
-
$(sel).attr("id");阅读@Rajaprabhu 答案 -
@Satpal 谢谢兄弟,它有效。
标签: javascript jquery