0

当我使用简单的本地数组时,我没有问题。我也没有问题从 MySQL 填充该数组。但是当我尝试加载一个对象数组时,即使是本地数组,它也不起作用。我错过了什么?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>autocomplete demo</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</head>
<body>
    <label for="autocomplete">Select a programming language: </label>
    <input id="autocomplete">
    <script>
    $( "#autocomplete" ).autocomplete({
        source: [ { label:"c++", value=1 }, { label: "java", value=2 }, { label: "javascript", value=3 } ]
    });
    </script>
</body>
</html>
4

1 回答 1

0

因为您为对象文字定义属性值的语法不正确:

[ 
    { 
        label:"c++", 
        value: 1 /* Be sure to use ":" and not "=" here */
    } 
]

使用:而不是=.

JSLintJSHint之类的工具将帮助您找到类似这样的简单错误。

示例:http: //jsfiddle.net/92Qjw/

于 2013-10-25T14:59:22.397 回答