我試圖將使用jQuery-UI的自動完成文本移動到輸入類型文本中。我只需點擊自動完成的文本並將其移入輸入。如何將自動完成jQuery-UI中的元素移動到輸入類型文本中單擊時
insert.php
<!DOCTYPE html>
<html>
<head>
<title> Home Page </title>
<link rel='stylesheet' type='text/css' href='style.css'>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" href="jqueryui.css">
</head>
<body>
<?php
echo"
<form id='form1' enctype='multipart/form-data' action='simpanpage.php' method='post'>
Label : <input type=text name=label id=label> <input type=submit value=save>
</form>
";
?>
<script>
$("#label").autocomplete({
source: "searchlabel.php",
minlength: 1,
select: function(event, ui) {
log(ui.item ?
"Selected Label: " + ui.item.value :
"Nothing selected, input was " + this.value);
}
});
</script>
</body>
</html>
searchlabel.php
<?php
include 'koneks.php';
$dba = new database;
$dba->connectMYSQL();
$arr = array();
if(isset($_GET['term']))
{
$term = $_GET['term'];
$query2 = "SELECT label FROM pages WHERE label LIKE '%$term%'";
$result2 = mysql_query($query2)
or die();
while($ans = mysql_fetch_row($result2)){
$arr[] = $ans[0];
}
echo json_encode($arr);
}
?>
能否請您解決我的問題?也許這裏的代碼有些問題。
是自動完成填充的數據? – Runcorn 2015-02-09 04:15:43
@Runcorn是的,但我不能點擊它們。 – 2015-02-09 04:24:18
所以你想在點擊建議時將選定的值複製到另一個輸入框中。 – Outlooker 2015-02-09 04:43:09