下面是我用来显示数据的自动完成jquery脚本。我在javascript中获取了值,但是在显示其不相关的数据时显示数据。
下面是我用来显示数据的自动完成jquery脚本。我在javascript中获取了值,但是在显示其不相关的数据时显示数据。
Data need to display is
3 1st Ave NW
但显示为
[
{
"
n
a
m
e
"
:"
3
1
s
t
A
v
e
N
W
"
}
]
脚本:
<script type="text/javascript">
var PLACEHOLDER = 'Enter Address Here';
var movieObjects;
var queryTerm;
$('[id$=addressTextBox]').autocomplete({
minLength: 2,
source: function(request, response) {
queryTerm = request.term;
code1WebServiceCallout1.getAddress(request.term, function(result, event){
if(event.type == 'exception') {
alert(event.message);
} else {
// alert(JSON.stringify(result[0]));
movieObjects = JSON.stringify(result);
//'{\"name\":\"31st Ave NW\"}';
response(movieObjects);
}
});
},
focus: function( event, ui ) {
$('[id$=addressTextBox]').val(ui.item.name);
return false;
},
select: function( event, ui ) {
$('[id$=addressTextBox]').val(ui.item.name);
//$('[id$=searchMovieId]').val( ui.item.Id );
return false;
},
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
var entry = "<a>" + item.label;
entry = entry + "</a>";
entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
return $( "<li></li>" )
.data( "item.autocomplete", item)
.append( entry )
.appendTo( ul );
};
// Add or remove placeholder values
$('[id$=addressTextBox]').val(PLACEHOLDER);
$('[id$=addressTextBox]').on("focus", function(event){
$tgt = $(event.target);
if($tgt.val() === PLACEHOLDER ){
$tgt.val('');
$tgt.removeClass('placeHolder');
}
});
$('[id$=addressTextBox]').on( "blur", function(event){
$tgt = $(event.target);
if($tgt.val() === '' ){
$tgt.val(PLACEHOLDER);
$tgt.addClass('placeHolder');
}
});
</script>