我有钥匙,VAL dict
这样的:试图通过关键,VAL字典迭代,并与另一匹配键循环
choices = {'first': 1, 'second': 2, 'third': 3}
然后,像这样一组的div:
<div class="choice_result">
<p class="choice_result_text">first<p/>
<span></span>
</div>
<div class="choice_result">
<p class="choice_result_text">second<p/>
<span></span>
</div>
<div class="choice_result">
<p class="choice_result_text">third<p/>
<span></span>
</div>
我想遍历每个.choice_result_text
,如果这.choice_result_text
== key
,我想要将该span
的html更改为val
。现在,我的jQuery代码(在Ajax成功功能)看起来是这样的:
result = $('.choice_result_text');
$.each(data.choices, function (key, val) {
$.each(result, function() {
if(result.html() == key) {
j = $('.choice_result').find('span').html(key);
j.html(val);
}
})
});
眼下,这个代码变成每span
在选择第一val
(1
)。任何想法如何使其正常工作?
为什么不与'choices'的关键标签使用一个ID? –
不确定你的意思。例如, – Zorgan
'
first
''。 –