2010-09-21 90 views
0

此代碼適用於firefox,但不適用於IE。有任何想法嗎?我正在使用最新的jQuery-ui庫。jquery ui自動完成 - 在IE中不工作

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8" /> 
<title>jQuery UI Autocomplete Remote datasource demo</title> 
<link type="text/css" href="jquery.ui.all.css" rel="stylesheet" /> 
<script type="text/javascript" src="jquery-1.4.2.js"></script> 
<script type="text/javascript" src="jquery.ui.core.js"></script> 
<script type="text/javascript" src="jquery.ui.widget.js"></script> 
<script type="text/javascript" src="jquery.ui.position.js"></script> 
<script type="text/javascript" src="jquery.ui.autocomplete.js"></script> 
<link type="text/css" href="demos.css" rel="stylesheet" /> 
<style type="text/css"> 
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif')  right center no-repeat; } 
.ui-autocomplete { 
    overflow-y: auto; 
    max-width: 400px; 
} 
/* IE 6 doesn't support max-width 
    * we use width instead, but this forces the menu to always be this wide 
    */ 
* html .ui-autocomplete { 
    width: 400px; 
} 
</style> 
<script type="text/javascript"> 

$(function() { 
function log(message) { 
    $("<div/>").text(message).prependTo("#log"); 
    $("#log").attr("scrollTop", 0); 
} 

$.ajax({ 
    url: "links2.xml", 
    dataType: "xml", 
    success: function(xmlResponse) { 
    var data = $("ROW", xmlResponse).map(function() { 
    return { 
     value: $("SC_DF_FIELD_1", this).text(), 
     url: $("SC_DF_FIELD_2", this).text(), 
     support_url: $("SC_DF_FIELD_3", this).text(), 
     description: $("SC_DF_FIELD_4", this).text(), 
     contact: $("SC_DF_PERSON_LINK", this).text() 

    }; 
    }).get(); 

    $("#_results").autocomplete({ 
    source: data, 
    minLength: 0 

    }).data("autocomplete")._renderItem = function(ul, item) { 
    return $("<li></li>") 
    .data("item.autocomplete", item) 
    .append("<a>" + item.value + "<br>" + item.url + "<br>" + item.description + "<br>" + "Support URL: " + item.support_url + "<br>" + "Contact: " + "<a href=" + item.contact + ">Test</a>" + "<br />" + "</a>") 
    .appendTo(ul); 
} 

    } 
}) 

}); 
</script> 

搜索:

回答

0

的代碼對我的作品在IE中。我看到的唯一區別是,我使用jQuery和jQueryUI的的googleapis版本:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script> 

唯一的其他可能的區別是標記,因爲你沒有張貼你的。我只是有一個這樣的輸入:

<input type="text" id="_results" /> 
+0

在鉻我看到我得到一個「原始null不允許通過訪問控制允許來源」錯誤更改我的來源到googleapi不會修復它在IE或鉻。我仍然在Chrome中遇到同樣的錯誤。 – specked 2010-09-21 15:36:08

+0

我也使用相同的輸入 – specked 2010-09-21 15:42:47

+0

這很奇怪。這個錯誤聽起來像是一個跨域AJAX錯誤。但我不知道爲什麼它會在FF中起作用,如果那是問題所在。鏈接2.xml文件與您的網頁在同一個域中是否在執行ajax? – fehays 2010-09-21 16:13:49