0

小提琴链接

如何将 div 附加到标签中。在每个无线电组及其包装器 div 中。

我有一个动态生成的单选按钮组代码,所以我不能使用 HTML 将静态帮助文本添加到标签中。

我将 div 放在无线电组 div 下,并添加带有帮助文本的 div,并用另一个 div 包装每个无线电组,然后使用 append。我正在使用类将其唯一的帮助文本 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>

<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>

````



4

1 回答 1

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'));

});


https://jsfiddle.net/praveendubbaka/t71oae3b/46/

于 2019-10-15T02:01:21.203 回答