【发布时间】:2014-09-04 22:55:16
【问题描述】:
有谁知道如何使用 jQuery Mobile 测试字段集的数据类型?我正在尝试更改水平放置的单选按钮的标签元素的背景颜色,但仅更改垂直放置的单选按钮的 ui-icon 背景颜色。只是无法弄清楚如何确定我的代码正在查看哪种类型的单选按钮。
任何想法将不胜感激!
这是我用来显示水平单选按钮的 html 代码块的示例。
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>* Are you a smoker?</legend>
<input type="radio" name="smoke" value="Yes" id="smokeY"/>
<label for="smokeY" class="radioButton">Yes</label>
<input type="radio" name="smoke" value="No" id="smokeN"/>
<label for="smokeN" class="radioButton">No</label>
</fieldset>
</div>
这是我用来显示垂直单选按钮的 html 代码块示例
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>* Do you have a vehicle in good working order?</legend>
<input type="radio" name="car" value="Yes" id="carY"/>
<label for="carY" class="radioButton">Yes</label>
<input type="radio" name="car" value="No" id="carN"/>
<label for="carN" class="radioButton">No</label>
</fieldset>
</div>
这是我正在使用的一半工作的 jQuery
for (group in radio_groups) {
if (!$(":radio[name=" + group + "]:checked").length) {
isValid = false;
$("input:radio[name=" + group + "]").each(function() {
/// this code changes the icon background of vertical radio buttons
$(this).next().find('.ui-icon').css('background-color', '#FF7575');
//// i think i need some kind of if statement here that can identify if the radio button
//// is horizontal or vertical
$(this).next().css('background', '#FF7575');
//// the above changes the lable background of horizontal radio buttons
});
} else {
$("input:radio[name=" + group + "]").each(function() {
$(this).next().find('.ui-icon').css('background-color', '#A7E9A7');
});
}
}
更新:
【问题讨论】:
标签: jquery html jquery-mobile radio-button radio-group