如何将div附加到标签中。在每个广播组及其包装区中。
我有一个动态生成的单选按钮组代码,因此无法使用HTML向标签添加静态帮助程序文本。
我将div放置在单选组div下,并在div中添加辅助文字,并用另一个div包裹每个单选组,然后使用append。我正在使用类将其唯一的帮助文本div添加到其标签中。
在屏幕before之前
在屏幕after
之后
<div class="helperTextWrapper" >
<div class="radioTable">
<div>
<span>
<label class="RadioButtonHelperText1">Yes</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText2">No</label>
</span>
</div>
</div>
<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
<div class="RadioButtonHelperTextLabel2">no helper text</div>
</div>
<div class="helperTextWrapper" >
<div class="radioTable">
<div>
<span>
<label class="RadioButtonHelperText1">Yes</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText2">No</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText3">Not sure</label>
</span>
</div>
</div>
<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
<div class="RadioButtonHelperTextLabel2">no helper text</div>
<div class="RadioButtonHelperTextLabel3">not sure helper text</div>
</div>
我想像这样使用jQuery将Yes辅助文本附加到Yes中,但是我的脚本添加了多个/重复的div:
$("div.helperTextWrapper ").each(function(index) {
$(this).find('.RadioButtonHelperTextLabel1').appendTo('.RadioButtonHelperText1');
$(this).find('.RadioButtonHelperTextLabel2').appendTo('.RadioButtonHelperText2');
$(this).find('.RadioButtonHelperTextLabel3').appendTo('.RadioButtonHelperText3');
});
<div class="helperTextWrapper" >
<div class="radioTable">
<div>
<span>
<label class="RadioButtonHelperText1">Yes
<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText2">No
<div class="RadioButtonHelperTextLabel2">no helper text</div>
</label>
</span>
</div>
</div>
</div>
<div class="helperTextWrapper" >
<div class="radioTable">
<div>
<span>
<label class="RadioButtonHelperText1">Yes
<div class="RadioButtonHelperTextLabel1">Yes helper text</div>
</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText2">No
<div class="RadioButtonHelperTextLabel2">no helper text</div>
</label>
</span>
</div>
<div>
<span>
<label class="RadioButtonHelperText3">Not sure
<div class="RadioButtonHelperTextLabel3">not sure helper text</div>
</label>
</span>
</div>
</div>
</div>
````
答案 0 :(得分:0)
$('.helperTextWrapper').each(function(){
$(this).find('.RadioButtonHelperTextLabel1').appendTo($(this).find('.RadioButtonHelperText1'));
$(this).find('.RadioButtonHelperTextLabel2').appendTo($(this).find('.RadioButtonHelperText2'));
$(this).find('.RadioButtonHelperTextLabel3').appendTo($(this).find('.RadioButtonHelperText3'));
});