Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
jQuery将文本替换为图像后将类添加到图像_Jquery - Fatal编程技术网

jQuery将文本替换为图像后将类添加到图像

jQuery将文本替换为图像后将类添加到图像,jquery,Jquery,我已经尝试了一些东西,但我不能让这个工作,我用下面的脚本来替换一些文字与图像,但我需要添加一个类这些图像 var $w = $( "#livescoring_summary" ), x = franchiseDatabase, y = 'fid_00', z = $( "#livescoring_summary" ).html(); for( i = 1; i<= 96; i++ ) { var j = (i < 10) ?

我已经尝试了一些东西,但我不能让这个工作,我用下面的脚本来替换一些文字与图像,但我需要添加一个类这些图像

   var $w = $( "#livescoring_summary" ),
        x = franchiseDatabase,
        y = 'fid_00',
        z = $( "#livescoring_summary" ).html();
for( i = 1; i<= 96; i++ ) {
   var j = (i < 10) ? y + '0' + i : y + i;
   z = z.replace( x[j].name, '<img src="' + x[j].icon + '" />' );
}
$w.html( z );

用图像替换文本并将其添加到dom后,运行以下操作:

$("#livescoring_summary img").wrap("<div class='your_class'></div>" );
$(“#livescoring#u summary img”).wrap(“”);
编辑

要仅包装“替换”的图像,请使用类标记它们并包装它们。大概是这样的:

...
z = z.replace( x[j].name, '<img src="' + x[j].icon + '" class="replaced" />' );
...
$("#livescoring_summary img.replaced").wrap("<div class='your_class'></div>" );
。。。
z=z.replace(x[j].名称“”);
...
$(“#livescoring#U summary img.已替换”).wrap(“”);

为什么不能将包装器div添加到
z.replace()
中?当我尝试时,它将不起作用,除非我做错了。。?示例?@MShack如果您可以设置JSFIDLE,我可以提供帮助。上述措施应该有效。我怀疑你的html设置不正确。您的文档是否有效?
$("#livescoring_summary img").wrap("<div class='your_class'></div>" );
...
z = z.replace( x[j].name, '<img src="' + x[j].icon + '" class="replaced" />' );
...
$("#livescoring_summary img.replaced").wrap("<div class='your_class'></div>" );