有谁知道如何测试哪些数据类型的字段集使用jQuery Mobile?我正在尝试更改水平放置的单选按钮的标签元素的背景颜色,但仅更改垂直放置的单选按钮的UI图标背景颜色。只是不知道如何确定我的代码正在查看哪种类型的单选按钮。jQuery检查哪些数据类型存在?
任何想法将不胜感激!
这是我用来显示水平单选按钮的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>
这是我使用显示垂直单选按钮
<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>
这里的HTML代码块的样品中途工作的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');
});
}
}
UPDATE:
我喜欢这个....你知道我会如何把它放在一起,使我现有的代码与你的建议一起工作吗? – Austin 2014-09-04 14:29:41
我添加了一个JSFiddle,可能会更有意义....任何帮助表示赞赏 – Austin 2014-09-04 14:45:57
@奥斯汀,看到我更新的答案。 – ezanker 2014-09-04 14:55:40