0

我正在使用以下教程从 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);
        });

    });

我希望能够在选择新选项后立即选择值

4

2 回答 2

0

this.value保存所选项目的值。

于 2013-07-22T16:20:56.537 回答
0

利用:

$("#demo-input-local").change(function(){
        var city = $(this).val();
        console.log(city);
});

演示:http: //jsfiddle.net/FlameTrap/uAhGJ/

于 2013-07-22T16:24:44.927 回答