[英]jquery autocomplete by textbox value
讓您考慮該值是否在textbox
所以現在如果我們鍵入它,它必須自動以逗號顯示具有多值的單詞。 我已經嘗試過,但是沒有結果。
任何機構都可以幫助解決這個問題。
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function()
{
var val = document.getElementById('tags').value;
var availableTags = val == '' : [] ? val.split(',');
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#tags" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "ui-autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tag programming languages: </label>
<input id="tags" size="25" value="ACCENTURE 1,
BPCL KORAMANGALA,
CUNNIGHAM ROAD,
HM TOWERS,
GREATER NOIDA,
INFOSYS 3,
JAYANAGAR T BLOCK,
MILLENIA,
OZONE,
BKC,
FUN REPUBLIC,
MATUNGA,
VFS UK,
CYBER GREEN,
PRABHADEVI,
VRINDAVAN"/>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.