将 jquery 数组中的值设置为跨度
Set values from jquery array to span
>我有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>
遍历所有at-radio-label
并将内容替换为具有相同索引的数组元素。
var fruit = ["111", "222", "333"];
$('.at-radio-label').each(function(i){
$(this).html(fruit[i]);
})
如果您不需要知道位置,只需按相同的顺序设置值。
fruit.forEach(function(value, i) {
var label = $(".at-radio-label")[i];
$(label).text(value);
});
看看这种方法:
<div id="inputs">
<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>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">
var fruit = ["111", "222", "333"];
for ( var i = 0, l = fruit.length; i < l; i++ ) {
$('#inputs span').eq(i).html(fruit[i]);
}
</script>
相关文章:
- 需要垫片设置-jquery.flot/jquery.flot.selection
- 是否可以在调用时动态设置Jquery Accordion的活动面板
- 无法在其他调用上设置jQuery对话框选项
- 如何在jquery ajax响应后设置jquery滑块的起始值
- 如何设置jQuery微调器的最大值和最小值
- 设置jquery按钮,而不是php错误和成功状态
- 设置jquery对话框的高度
- 如何动态设置jquery mobile'的minHour选项;s的日期框
- 如何正确设置jQuery日历小部件的区域设置
- 如何设置jQuery函数的动画's循环中的变量
- 设置 Jquery 对话框标题栏样式
- 如何使用JQuery.Load访问Div中加载URL的UL“id”,“name”等,以设置JQuery树视图
- 如何在页面加载时设置 jquery 切换关闭
- 根据 HTML 表单 ID 值动态设置 jquery 选择器
- 在 jquery 表单序列化变量中设置 jquery 延迟
- 设置 jQuery 动画的队列长度
- 从 html 数据设置 jquery 延迟
- 设置JQuery动画中的超时
- 根据 C# 值设置 jQuery cookie 的值
- 无法设置 jquery 对话框.InnerHtml(某些内容)无需刷新页面