Jquery随机使用多个同名、不同背景的类

Jquery随机使用多个同名、不同背景的类,jquery,css,image,background,Jquery,Css,Image,Background,标题应该说这一切真的,我有4个图像,5个类都命名相同。图像应用于前4个类(同样,它们是相同的类名),第5个类不添加图像(请参见附件图像)。我希望图像在每个类上随机显示。我还希望图像是随机的。 这是我的密码 $("table.catalogFooterArea").css("background", function(i) { return [ "url(Custom/themes/pilot/css/images/catItemFoot.png)", "url(Custom/t

标题应该说这一切真的,我有4个图像,5个类都命名相同。图像应用于前4个类(同样,它们是相同的类名),第5个类不添加图像(请参见附件图像)。我希望图像在每个类上随机显示。我还希望图像是随机的。

这是我的密码

$("table.catalogFooterArea").css("background", function(i) {
  return [
   "url(Custom/themes/pilot/css/images/catItemFoot.png)",
   "url(Custom/themes/pilot/css/images/catItemFoot2.png)",
   "url(Custom/themes/pilot/css/images/catItemFoot3.png)",
   "url(Custom/themes/pilot/css/images/catItemFoot4.png)"][i];
});

谢谢mplungjan忘了使用。每个

随机什么?要获取随机索引,您需要Math.floor(Math.random()*imageArray.length)对不起,我想在每个表上放置一个随机背景图像。catalogFooterArea我做了Math.random,但它在所有类表上都放置了相同的img。catalogFooterArea此方法有效,但只会将图像添加到前4个表中。catalogFooterArea。我想做的是,在table.catalogFooterArea的背景中随机添加一个图像,然后使用.each并测试是否已经拍摄了随机图像
var images = ['catItemFoot.png', 'catItemFoot2.png', 'catItemFoot3.png', 'catItemFoot4.png'];

$("table.catalogFooterArea").each(function(){
  $(this).css({'background' : 'url(custom/themes/pilot/css/images/' + images[Math.floor(Math.random() * images.length)] + ')'})
   });