gpt4 book ai didi

javascript - jquery-ui-autocomplete 填充其他输入

转载 作者:行者123 更新时间:2023-11-27 23:42:58 25 4
gpt4 key购买 nike

我使用以下代码,

JS

<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}

$( "#input" ).autocomplete({
source: "source.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"SelectedName: " + ui.item.value + " -SelectedID: " + ui.item.ID:
"Nothing selected, input was " + this.value );
}
});

PHP/HTML

<tr>
<td colspan="2">Input</td>
<td colspan="2" >
<input class="glowing-border" id="input">
</td>
</tr>


<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>

这非常有效。但我被困在这里,因为我想将结果分成两部分。现在,在 div 中显示:

"selectedName: theName - SelectedID: 12345"

但是,我需要用这两个值填充另一个输入字段,有一个输入字段 <input id="selectedText">和一个<input id="selectedID">

我该怎么做?

2.)当我在“输入”中输入内容时,我仅从数据库中获取匹配的文本。是否可以在列表框中显示 ID?

最佳答案

类似这样的吗?

$( "#input" ).autocomplete({
source: "source.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"SelectedName: " + ui.item.value + " -SelectedID: " + ui.item.ID:
"Nothing selected, input was " + this.value );
if (ui.item){
$("#selectedText").val(ui.item.value);
$("#selectedID").val(ui.item.ID);
}
}
});

关于javascript - jquery-ui-autocomplete 填充其他输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33502773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com