代码:
<script>
$(function() {
$( "#university_name" ).autocomplete({
source: 'autocomplete.php',
minLength:2,
select: function(event, ui) {
var x = ui.item.value;
}
});
});
</script>
<input type="text" id = "university_name" name = "university_name" value= "x" placeholder = "University Name" >
这里我想将jquery变量值,即var x放入输入字段值那么我们怎么做呢?
谢谢
答案 0 :(得分:1)
你可以使用jquery val()
$('#university_name').val(x);
您的完整代码将如下所示
$( "#university_name" ).autocomplete({
source: 'autocomplete.php',
minLength:2,
select: function(event, ui) {
var x = ui.item.value;
$('#university_name').val(x);
}
});