名称中没有空格的关联数组不会出现

时间:2015-06-08 11:19:36

标签: javascript php jquery

这些是我用来填写表格的值:

var champions = {
    "Azir":["Shurima's Legacy","Conquering Sands","Arise!","Shifting Sands", "Emperor's Divide"],
    "Dr. Mundo":["Shurima's Legacy","Conquering Sands","Arise!","Shifting Sands", "Emperor's Divide"]
    };

问题在于空间而不是Mundo博士,因为博士无论如何都要解决这个问题吗?

更新

echo '<input class="champion" type="text" list="champions" placeholder="Champion '.$i.'" name="champno[]" required autofocus><br/>
                            <datalist id="champions"></datalist>';

Jquery的:

for(var key in champions){
            if(champions.hasOwnProperty(key)){
                $('#champions').append('<option value=' + key + '>');
            }
        }

1 个答案:

答案 0 :(得分:3)

引用该值:

for(var key in champions){
        if(champions.hasOwnProperty(key)){
            $('#champions').append('<option value="' + key + '">');
        }
    }

或者,您应该使用类似的东西(对于演示,未经测试):

$('#champions').append($('<option>').attr('value', key));