我有这个初始化:
var myField1 = $('#field1');
var myField2 = $('#field2');
var allFields = $( [] ).add( myField1 ).add( myField2 );
其中$('#field1')和2是对话框的输入文本字段,我正在尝试更新myField1,所以我尝试了:
itemDetails['myField1'] = "Test Fill Field";
allFields[myField1] = itemDetails['myField1'];
但它没有填补......我应该错过或错过什么?
提前致谢! 干杯, 路易
答案 0 :(得分:0)
您尚未初始化itemDetails
数组。这有效:
OP评论后编辑:您是否想要实现这一目标?
var myField1 = $('#myField1');
var myField2 = $('#myField1');
var allFields = [myField1, myField2];
var itemDetails = [];
itemDetails['myField1'] = "Test Fill Field";
allFields[0].val(itemDetails['myField1']);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="myField1" name="myField1" value="myField1">
<input type="text" id="myField2" name="myField1" value="myField2">
&#13;