我有一个动态生成的表单,其中用户选择Kids的数量,并动态生成所选的数字字段。设计使用Bootstrap radio button group
来选择性别。
我能够生成表单和验证,但它有两个问题:
Success
时,css类不会自动应用。Clicked
属性。下面是正确工作的表单部分的标记,其中单击它们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事件。 感谢