は、以下のデータをJSONファイル想像:私はそれを選択して値を挿入するためのオプションとしてカラーを表示できるようにしたい、jQueryのオートコンプリートメソッドを使用してオートコンプリートjQueryの使用JSONデータ
[
{
color: "red",
value: "#f00"
},
{
color: "green",
value: "#0f0"
},
{
color: "blue",
value: "#00f"
},
{
color: "cyan",
value: "#0ff"
}
]
を入力上に。
<input type="text" name="selector" id="selector" />
<input type="text" name="color" id="color" />
<input type="text" name="value" id="value" />
上記の説明は必要ありません。色の検索のセレクタの色とinput.value
との値の値を持つinput.color
の検索のセレクタ。
EDIT:
[{
"label": "Sec\u00e7\u00e3o 1",
"value": "1"
}, {
"label": "Sec\u00e7\u00e3o 2",
"value": "2"
}, {
"label": "Sec\u00e7\u00e3o 3",
"value": "3"
}, {
"label": "Sec\u00e7\u00e3o 4",
"value": "4"
}]
このHTML::
<input type="text" id="name" />
<input type="text" id="value" />
と、このjQueryの:私はアンドリューの答えと、それに続く
$(document).ready(function(){
$("#name").autocomplete({
source: "json.php",
select: function (event, ui) {
$("#name").val(ui.label);
$("#value").val(ui.value);
}
});
});
私は、このJSONデータを持っている データを選択するように求められますが、01に警告するととui.value
の変数は、 'undefined'と表示されます。私は何が欠けていますか?
EDIT2: だが、私はこのHTMLを持っているとしましょう:
<input type="text" class="name" />
<input type="text" class="value" />
<input type="text" class="name" />
<input type="text" class="value" />
は同じ.autocomplete()
の方法で複数のセレクタを処理することが可能ですか?同様に、input.name
を使用してラベルを選択し、その隣のinput.value
のみを更新しますか?
[input.name] [input.value]
^私は隣に
ラベル 値を更新^ を選択[入力名] [入力値]
^これは、リモート・データ・ソースを使用して、完全な^
リモートまたはローカルのデータソースを使用していますか? –
これは、DBから値を取得し、JSON形式でそれらをエンコードするPHPファイルになります... – silentw
jQueryのオートコンプリートを使用する正しい方法が何であるか把握しようとしていたので、私はまだ試していません... – silentw