我有html代码:

<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='topbanner' />
<span class='at-radio-label'>topbanner</span>
<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='undermenu' />
<span class='at-radio-label'>undermenu</span>
<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='topstring' />
<span class='at-radio-label'>topstring</span>

如何将.at-radio-label中的值替换为数组中的值,如:
var fruit = ["111", "222", "333"];

生成的html代码应如下所示:
<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='topbanner' />
<span class='at-radio-label'>111</span>
<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='undermenu' />
<span class='at-radio-label'>222</span>
<input type='radio' class='at-radio' name='re_widget[0][set_style_for_widget]' value='topstring' />
<span class='at-radio-label'>333</span>

最佳答案

如果不需要知道位置,只需按相同的顺序设置值。

fruit.forEach(function(value, i) {
    var label = $(".at-radio-label")[i];
    $(label).text(value);
});

09-25 19:40