简体   繁体   中英

Jquery behave differently on firefox and chrome

Following personnel, I have these commands that get the border colors and background of each div:

 var data_id =  $('#Topo').css('border-color') + $('#Topo').css('background-color') + $('#senha_12').css('border-color') + $('#senha_12:hover').css('border-color') + $('#senha_12').css('background-color');

$.ajax({
      type: "POST",
      url: "funcoes/a-php/ler/ler_config.php",
      data: data_id,
      cache: false,
      success: function(data_o){
        alert(data_o);
      }
  });

What is happening is the following, these divs that are caught up through the jQuery as follows:

<style>
#senha_12{
    margin-left:15px;
    float:left;
    margin-top:3px;
    width:72px;
    height:68px;
    background:#FFFFFF;
    border:2px solid #A3C2FF;
    border-radius:10px; 
    cursor:pointer;
}
#senha_12:hover{
    cursor:pointer;
    border:2px solid #FF6600;
    float:left;
}
</style>

<div id="Topo" style="border-radius:10px; width:150px; margin-left:-5px; margin-top:30px; text-align:center;  height:80px; float:left;  background:url(background.png); border:2px solid #060606;">
<div id="senha_12">
<img src="design/imagens/2.fw.png" style="margin-top:10px" width="52" height="48">
</div>
<img src="design/imagens/1.fw.png" style="margin-top:10px" width="32" height="32">
</div>

In this case, I gave the users the freedom to modify the color of each div, using a command that opens a box with various colors, and so a color is selected is caught rgb and jQuery does div to update the own color User chose that (but that's beside the point, so I expressed this to avoid those questions 'but because you want to take this?')

In Google Chrome, these colors are handles through the JavaScript and are thrown for a project in PHP in PHP and it takes each parameter and puts in an array, the result is shown as follows:

排列

Already on Firefox I do not know what is actually happening, but some came from fields blank (even editing the colors through the above command):

排列

In hindsight, this error in Firefox does not seem to be in error parameters in PHP, I believe is a problem with Firefox same ... believe there is any exception in Firefox that prevents take the color of divs. I wonder why this is happening and also a possible solution to this problem.

jQuery uses window.getComputedStyle(element) when you call css .

The property border-color does not really exist, but is a shorthand for border-[left|top|right|bottom]-color .

FireFox does not return a value of any of these shorthand if window.getComputedStyle(element) is used. WebKit (afaik) only returns a value for the shorthand if all of the properties it represents have the same value.

If you are sure, that the color is the same for all sides, then you could think over calling $('#Topo').css('border-left-color') instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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