简体   繁体   English

使用jQuery无法在firefox中复制背景从一个元素复制到另一个元素

[英]Copy background from one element to another using jQuery not working in firefox

Here's a jsfiddle - http://jsfiddle.net/XcC5d/1/ 这是一个jsfiddle - http://jsfiddle.net/XcC5d/1/

$('.select').on('click', function(event){
    $('.result').css('background', $(event.target).css('background'));
});

When clicking on any of the first 3 .select divs, it copies the background css value and sets it to the result with the red border. 单击前3个.select div中的任何一个时,它会复制背景css值并将其设置为带有红色边框的结果。

This works in safari and chrome but not in firefox. 这适用于safari和chrome,但不适用于Firefox。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Try the following: 请尝试以下方法:

$('.select').on('click', function(event){
    $('.result').css('background', $(event.target).css('background-image'));
});

You should set the background-image property of the CSS. 您应该设置CSS的background-image属性。 Like this: Update of your fiddle 像这样: 更新你的小提琴

$('.select').on('click', function(event){
    $('.result').css('background', $(event.target).css('background-image'));
});

Edit: Damn, few seconds too late :) 编辑:该死,几秒钟太晚了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM