【发布时间】:2011-03-31 18:47:16
【问题描述】:
我正在使用 JQM (jQueryMobile) 并且需要要求一个组中的所有复选框,直到选中一个,然后只要求选中的一个,除非它是选中所有然后要求所有。
问题是我不能使用复选框组的Id或Name属性,所以我尝试使用class属性。
这是一个标记示例(但功能不起作用):http://jsfiddle.net/HfLq3/7/
HTML:
<div data-role="page">
<form id="chips_form" name="chips_form" action="#" method="post">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose as many snacks as you'd like:</legend>
<input type="checkbox" name="checkbox-1a" id="checkbox-1a" class="custom chips" />
<label for="checkbox-1a">Cheetos</label>
<input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom chips" />
<label for="checkbox-2a">Doritos</label>
<input type="checkbox" name="checkbox-3a" id="checkbox-3a" class="custom chips" />
<label for="checkbox-3a">Fritos</label>
<input type="checkbox" name="checkbox-4a" id="checkbox-4a" class="custom chips" />
<label for="checkbox-4a">Sun Chips</label>
<input type="checkbox" name="checkbox-5a" id="checkbox-5a" class="custom chips" />
<label for="checkbox-5a">Select All</label>
</fieldset>
</div>
<div data-role="fieldcontain">
<button type="submit" name="submit" value="chips-submit">Submit</button>
</div>
</form>
</div>
JS:
$(".chips").change(function() {
alert('selected Value(s): '+$(this).val());
});
$('.chips').each(function() {
$(this).attr('required','required');
});
【问题讨论】:
标签: jquery html checkbox jquery-mobile