css类并在动态创建的单选按钮组中单击丢失?

时间:2014-11-24 22:36:45

标签: jquery html css twitter-bootstrap

我有一个动态生成的表单,其中用户选择Kids的数量,并动态生成所选的数字字段。设计使用Bootstrap radio button group来选择性别。

我能够生成表单和验证,但它有两个问题:

  1. 选择按钮Success时,css类不会自动应用。
  2. 点击按钮后,它不会向其添加Clicked属性。
  3. 下面是正确工作的表单部分的标记,其中单击它们css和Clicked:

        <div class="toggle-btn-grp joint-toggle">
      <label class="toggle-btn clicked">
    
        <input type="radio" name="ApplicantDetails.Gender" class="visuallyhidden" id="male2" value="m">
        Male
      </label>
      <label class="toggle-btn clicked success">
    
        <input type="radio" name="ApplicantDetails.Gender" class="visuallyhidden" id="female2" value="f">
        Female
      </label>
    </div>
    

    这是我生成动态标记的Jquery代码:

        function GetGenderMarkup(itrator)
    {
        var ret = "<div id='Dependent" + itrator + "Gender' class='field rf-field'>"
                   +"<label>Gender</label>"
                   +"<div class='toggle-btn-grp joint-toggle'>"
                     +"<label class='toggle-btn'>"
                       +"<input required='' type='radio' value='m' id='male2' class='visuallyhidden'"
                              +"name='DependentDetails[" + itrator + "].Gender'>"
                           +"Male"
                     +"</label>"
                     +"<label class='toggle-btn'>"
                       +"<input type='radio' value='f' id='female2' class='visuallyhidden'" 
                              +"name='DependentDetails[" + itrator + "].Gender'>"
                         +"Female"
                     +"</label>"
                   +"</div>"
                 +"</div>";
        return ret;
    }
    

    ,最后是上面代码生成的标记:

    <div class="toggle-btn-grp joint-toggle">
      <label class="toggle-btn">
        <input type="radio" name="DependentDetails[0].Gender" class="visuallyhidden" id="male2" value="m" required="">
        Male
      </label>
      <label class="toggle-btn">
        <input type="radio" name="DependentDetails[0].Gender" class="visuallyhidden" id="female2" value="f">
        Female
      </label>
    </div>
    

    请帮助并指导我缺少的内容以及如何在非生成表单中添加css和clicked事件。 感谢

0 个答案:

没有答案