Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 每个。(函数)中的Jquery代码不起作用_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 每个。(函数)中的Jquery代码不起作用

Javascript 每个。(函数)中的Jquery代码不起作用,javascript,jquery,html,css,Javascript,Jquery,Html,Css,下面是Js代码 $(".productwrapcart").each(function(){ var addbg = $(this).find(".cartfeat img").attr('src'); $(this).find(".incartbttn").css('background-image','url(' + addbg + ')'); }); js的想法是从多个相似项循环的项中的隐藏表中提取内容 出于某种原因,这段代码中的代

下面是Js代码

$(".productwrapcart").each(function(){
  var addbg = $(this).find(".cartfeat img").attr('src');
  $(this).find(".incartbttn").css('background-image','url(' + addbg + ')');                        
});
js的想法是从多个相似项循环的项中的隐藏表中提取内容

出于某种原因,这段代码中的代码不起作用

$(".productwrapcart").each(function(){});

我一把它放在外面,它就开始工作了…

这意味着.productwrapcart与任何元素都不匹配,因此没有每个元素可以运行。在浏览器控制台中运行$.productwrapcart并检查结果。你能分享你的HTML吗?什么是不工作?什么都没发生?或者发生了一些事情,但不是你所期望的?或者…?好的,我想你需要展示一个html的示例。考虑也提供演示。