2014-02-27 62 views
0

這是jQuery代碼,適用於Firefox和IE,但不適用於Chrome瀏覽器。 我放置alert()進行調試,它不適用於chrome或safari。有任何想法嗎? ( 「locationoption」)。 的bxslider jQuery的作品,但不是$點擊(函數() 這裏是代碼:jQuery點擊不適用於Chrome瀏覽器

$(document).ready(function(){ 

    $(".locationoption").click(function() { 
     var datastring = "location="+$("#locationselection").val()+"&language="+"<?php echo $language; ?>"; 

     alert(datastring); 

     $.ajax({ 
      type: "POST", 
      url: "includes/ajaxlocationsearch.php", 
      data: datastring, 
      cache: true, 
      success: function (data) { 
       $("#hotelselection").html(data); 
      } 
     }); 
    }); 

    $('#leftsidebarbanners').bxSlider({ 
    controls:true, 
    nextText:" Next &#8594;", 
    prevText:"&#x2190; Previous |", 
    }); 

}); 
+0

您的開發工具中是否有任何錯誤?嘗試將alert(「Hello」)作爲點擊函數中的第一項。如果這個作品你知道這是字符串的問題。 –

+0

你能否包含相關的html? –

+0

您是否已經試過''('。locationoption「)on('click',function()'? – Jurik

回答

3

我猜是因爲它是不是一個真正的DOM元素,你不應該使用的點擊「選項」元素 我猜。它完全由瀏覽器繪製,並且您注意到它可以根據瀏覽器的不同而有所不同。

但是使用select的change事件:「#locationselection」。並且可能使用以下語法來填充數據:

$("#locationselection").change(function() { 
    $.ajax({ 
     type: "POST", 
     url: "includes/ajaxlocationsearch.php", 
     data: { 
      location: $(this).val(), 
      language: "<?php echo $language; ?>" 
     }, 
     cache: true, 
     success: function (data) { 
      $("#hotelselection").html(data); 
     } 
    }); 
}); 
+0

非常感謝,它的工作原理!!! :) – GeorgeGeorgitsis

+0

太棒了!不客氣:) – KoalaBear

0

您可以嘗試使用jQuery代表 Link to JQuery documentation

當初與我的網站上藏漢和委託動態地加載內容的問題完全爲我工作。

$("id of class of outer element").delegate("id/class/element of content that is to be clicked", "click", function() { 
     //do your stuff 
); 
+0

不,它沒有工作... – GeorgeGeorgitsis

相關問題