我有一个带有jquery自动完成功能的输入文本框。每当我尝试与盒子进行交互时,都不会显示自动完成备选方案。在用于调试Chrome的工具中,我收到错误“Uncaught TypeError:无法读取未定义的属性'元素'”。 当我在框中添加inputtype时,控制台错误会添加另一个。 这是JS文件:
$(document).ready(function($) {
$("input#insegnapag").autocomplete({
delay: 300,
minLength: 0,
source: function(request, response) {
var reqdem = request.term;
str_data = "insegna=" + reqdem + "&categ=" + $("#categor").val(); // + "&lat=" + $("#lat").val() + "&lng=" + $("#lng").val() ;
$.ajax({
url: '/php-cmd/estraiNomiInsegna.php',
dataType: "json",
type: 'GET',
async: false,
data: str_data,
success: function(data) {
var array = data.error ? [] : $.map(data, function(m) {
return {
label: m.insegna,
value: m.insegna
};
});
response(array);
}
});
},
focus: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
$(this).val(ui.item.label);
},
select: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
// navigate to the selected item's url
$(this).val(ui.item.label);
$("#insegnapag").val(ui.item.value);
$("#insegna").val(ui.item.value);
}
});
$("input#insegnapag").keydown(function(event) {
if (event.keyCode === 13) {
var destination = 'http://www.trovavolantini.it/volantino/' + $("#insegnapag").val() + '/' + $("#citta").val();
$("#insegnapag").val($("#insegnapag").val());
window.location.href = destination;
event.preventDefault();
}
});
$("#citta").keydown(function(event) {
if (event.keyCode == 13) {
var destination = '';
if ($("#insegnapag").val() == '') {
destination = 'http://www.trovavolantini.it/volantino-categoria/' + $("#categoria").val() + '/' + $("#citta").val();
}
else {
destination = 'http://www.trovavolantini.it/volantino/' + $("#insegnapag").val() + '/' + $("#citta").val();
}
$("#localita").val($("#citta").val());
$("#citta").val($("#citta").val());
//alert ($("#localita").val());
window.location.href = destination;
event.preventDefault();
// return false;
}
});
这是带有包含文件的.PHP文件的一部分:
<link href="/css/global-res.css" rel="stylesheet" type="text/css" />
<link href="/css/style.css" rel="stylesheet" type="text/css" />
<link href="/css/insegna-dk.css" media="(min-width:1080px)" rel="stylesheet" type="text/css" />
<link rel="stylesheet" media="(max-width:1080px)" href="/css/insegna-small-650.css" type="text/css">
<link rel="stylesheet" href="/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<link href="/css/ui-lightness/jquery-ui-1.10.2.custom.css" rel="stylesheet" />
<link rel="stylesheet" media="(max-width:1080px)" href="/css/global-small-650.css" type="text/css"/>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-516ecf974aa275c4" async></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="/js/ui/jquery.ui.autocomplete.js" type="text/javascript" async ></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places®ion=it&language=it&sensor=false"></script>
<script type="text/javascript" src="http://www.trovavolantini.it/js/utility.js"></script>
<script type="text/javascript" src="/js/volantino.js"></script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
和输入文本的部分代码:
<form id="form2" metod="POST" action="">
<h2 style="z-index:10;" class="menu-loc"><strong>Offerte <?php echo $VolCat; ?> <span class="tooltip" title="Cerca un'insegna"><input type="text" class="selectcity" id="insegnapag" value="<?php echo $insegna; ?>"/></span> vicino a
<span class="tooltip" title="Non sei qui? Cambia"><input type="text" class="selectcity" id="citta" value="<?php echo $localita; ?>"/><input type="hidden" id="idloc" name="idloc"/></span>
<input type="hidden" id="localita" name="localita" value="<?php echo $localita; ?>" />
<!--<input type="hidden" id="insegna" name="insegna" value="<?php echo $insegna; ?>" />--> </strong>
<span style="font-size:0.8em"><a href="javascript:newUrl();" id="cambia_localita">
<span>Cambia</span></a></span><img src="/images/puntatore-citta.png" title="Volantino <?php echo $insegna; ?> vicino a <?php echo $localita; ?>" alt="Volantino <?php echo $insegna; ?> vicino a <?php echo $localita; ?>" width="26" height="40" align="absmiddle" /><a href="javascript:geolocalizzami()" id="Geolocalizza"><img src="/images/sono-qui.png" style="padding-left: 45px" align="absmiddle" alt="Sono qui!" title="Sono qui!"/></a></h2>
<input type="hidden" id="localitachange_data" name="localita" value="<?php echo $localita; ?>"/>
<input type="hidden" id="lat" name="lat" value="<?php echo $lat_curr; ?>"/>
<input type="hidden" id="lng" name="lng" value="<?php echo $lng_curr; ?>"/>
<input type="hidden" id="categor" name="categor" value="<?php echo $idcat; ?>"/>
</form>
你可以看到这一切 http://www.trovavolantini.it/volantino-categoria/Iper%20e%20Super