[英]autocomplete jQuery.noConflict
我想向現有頁面添加新的自動完成輸入,該頁面已經使用了捆綁版本的jQuery。 因此,我需要使用jQuery.noConflict()
。
在此頁面之外,我的代碼可以正常工作,但是在現有頁面上,我不知道如何使其工作。
我總是收到錯誤$ (...).autocomplete is not a function
。
這是我使用的代碼:
// .....code from existing page with already loaded jQuery script
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
$.noConflict();
jQuery( document ).ready(function( $ ) {
/* Make the AJAX request once for the source array: */
$.getJSON("./mapdata/get_list_json.php", function (data) {
$("#parzelle").autocomplete({
minLength: 3,`enter code here`
source: data,
dataType: "json",
select: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
// manually update the textbox and hidden field
$(this).val(ui.item.label);
$("#gid").val(ui.item.value);
}
});
});
});
抱歉,但是我也對代碼做了一些更改。 因此,這就是我的工作方式:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
// .....code from existing page with already loaded jQuery script
$J = jQuery.noConflict();
$J( document ).ready(function( $J ) {
//$(function () {
/* Make the AJAX request once for the source array: */
$J.getJSON("./mapdata/get_parzellen_list_json.php", function (data) {
$J("#parzelle").autocomplete({
minLength: 3,
source: data,
dataType: "json",
select: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
// manually update the textbox and hidden field
$J(this).val(ui.item.label);
$J("#gid").val(ui.item.value);
}
});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.