我有一个动态生成的数组集合。我想要做的是实现一个自动完成功能。我想在click事件处理程序中使用这些数组,通过动态获取名称并将其分配给本地数组。但是,这是行不通的(我不知道我的代码)。有什么办法可以实现吗?动态创建名称为java的脚本数组脚本字符串
这里是我的代码,我认为应该工作(不工作):
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<script>
var ga_input1 = new Array('India','Russia','Norway');
var ga_input2 = new Array('Delhi','Mumbai','Hyderabad');
</script>
<body>
Countries: <input id="input1" type="text"/>
Cities: <input id="input2" type="text"/>
<script>
var arrayTmp = new Array();
$('input').keydown(function(){
var id = $(this).attr('id');
arrayTmp = "ga_"+id; // What I believe here is the values of ga_input1/ga_input2 are assigned to array 'arrayTmp'
//alert(arrayTmp[0]);
});
</script>
</body>