2013-10-10 84 views
0

我有這段代碼在mozilla上工作,但不能在webkit瀏覽器上工作。jQuery腳本不能在webkit瀏覽器上工作

它是簡單的腳本,點擊與指定的值,並顯示圖像。 然後其他的,得到禁用attr。

任何人都可以幫助我承擔爲什麼它不在webkit中工作。

信息:它是一個FB應用,致力於小籌碼

感謝

的代碼:

<script type="text/javascript"> 
$(document).ready(function() { 

$('#image,#image2,#image3,#image4,#image5').hide(); 

    $('option').click(function(e) { 
    switch ($(this).attr('value')) { 

     case 'ATENTA': 
     $("#image").show().click(function(){ 
      $(this).hide(); 
     }); 
     e.preventDefault(); 
     break; 

     case 'CREATIVA': 
     $("#image2").show().click(function(){ 
      $(this).hide(); 
     });  
     e.preventDefault(); 
     break; 

     case 'COQUETA': 
     $("#image4").show().click(function(){ 
      $(this).hide(); 
     });   
     e.preventDefault(); 
     break; 

     case 'PEGOTE': 
     $("#image3").show().click(function(){ 
      $(this).hide(); 
     });  
     e.preventDefault(); 
     break; 

     case 'COLGADA': 
     $("#image5").show().click(function(){ 
      $(this).hide(); 
     });  
     e.preventDefault(); 
     break; 
    } 
    }); 

    $('select').change(function(){ 
    var value = $(this).val(); 
    $(this).children('option').each(function(){ 
     if ($(this).val() === value) { 
      $(this).siblings('option').attr('disabled', true); 
     } 
     }); 
    }); 

}); 

回答

0

我猜有什麼不工作是圖像的實際負荷。我認爲這是因爲這一點代碼:

$('option').click(function(e) { 

瀏覽器以不同的方式處理表單元素。例如,點擊select中的選項可能觸發firefox的「點擊」事件,但不會觸發Chrome。

嘗試是這樣的:

$(document).ready(function() { 

    $('#image,#image2,#image3,#image4,#image5').hide(); 


    $('select').change(function() { 
     var value = $(this).val(); 

     $(this).children('option').each(function(){ 
      if ($(this).val() === value) { 
       $(this).siblings('option').attr('disabled', true); 
      } 
     }); 

     switchImage(value); 
    }); 

    var switchImage = function(toLoad) { 
     switch (toLoad) { 

      case 'ATENTA': 
      $("#image").show().click(function(){ 
       $(this).hide(); 
      }); 
      break; 

      case 'CREATIVA': 
      $("#image2").show().click(function(){ 
       $(this).hide(); 
      }); 
      break; 

      case 'COQUETA': 
      $("#image4").show().click(function(){ 
       $(this).hide(); 
      }); 
      break; 

      case 'PEGOTE': 
      $("#image3").show().click(function(){ 
       $(this).hide(); 
      }); 
      break; 

      case 'COLGADA': 
      $("#image5").show().click(function(){ 
       $(this).hide(); 
      }); 
      break; 
     } 
     }); 
    }; 

}); 

這是什麼東西做的是使用上的選擇標籤本身的「變」事件調用switchImage功能,而不是依賴於「click」事件的選項標籤。

+0

謝謝恩裏克!這對我很有幫助。你救了我的命 ;) – user2657175

相關問題