我使用以下教程从json列表填充下拉菜单:http://loopj.com/jquery-tokeninput/
我特别使用以下代码:
$(document).ready(function() {
$("#demo-input-local").tokenInput([
{name: "Ruby"},
{name: "Python"},
{name: "JavaScript"},
{name: "ActionScript"},
{name: "Scheme"},
{name: "Lisp"},
{name: "C#"},
{name: "Fortran"},
{name: "Visual Basic"},
{name: "C"},
{name: "C++"},
{name: "Java"},
{name: "Taranto"}
]);
$("#demo-input-local").change(function(){
var city = // get the selected value on change
console.log(city);
});
});
我希望能够在选择新选项后立即选择值
答案 0 :(得分:0)
this.value
保存所选项目的值。
答案 1 :(得分:0)
使用:
$("#demo-input-local").change(function(){
var city = $(this).val();
console.log(city);
});