我正在尝试为图片添加一些无缓存前缀:
var cacheId = Math.floor(Math.random() * 10000) + 1;
$(this).attr('src', src + cacheId);
但我有一个错误:src is not defined
,出了什么问题?
答案 0 :(得分:1)
您的名为src
的变量目前尚未定义。
我相信你想做这样的事情。 Fiddle
$(document).ready(function () {
$("img").each(function () {
var src = $(this).attr('src');
var cacheId = Math.floor(Math.random() * 10000) + 1;
$(this).attr('src', src + "?r=" + cacheId);
});
});