<h3>5. 如果您在***网预订过酒店,预订过的是几星级的酒店?(可多选) </h3> <div id="item5"> <input name="hotelStar" id="hotelStar-1" value="1" type="checkbox">经济型 <input name="hotelStar" id="hotelStar-2" value="2" type="checkbox">三星级 <input name="hotelStar" id="hotelStar-3" value="3" type="checkbox">四星级 <input name="hotelStar" id="hotelStar-4" value="4" type="checkbox">五星级 <input name="hotelStar" id="hotelStar-5" value="5" type="checkbox">没有预订过酒店 <span id="hotelStar-error"> </span></div> <h3>6. 如果您在***网预订过酒店,平均隔多久在本网站上预订一次?</h3> <div id="item6"> <input name="bookInterval" id="bookInterval-1" value="1" type="radio">1周 <input name="bookInterval" id="bookInterval-2" value="2" type="radio">1月 <input name="bookInterval" id="bookInterval-3" value="3" type="radio">1季度 <input name="bookInterval" id="bookInterval-4" value="4" type="radio">1年 <input name="bookInterval" id="bookInterval-5" value="5" type="radio">>1年 <input name="bookInterval" id="bookInterval-6" value="6" type="radio">没有预订过酒店 <span id="bookInterval-error"> </span></div> 。。。 <h3>12. 在本网站您主要为谁预订酒店?(可多选)</h3> <div id="item12"> <input name="orderFor" id="orderFor-1" value="1" type="checkbox">自己旅游 <input name="orderFor" id="orderFor-2" value="2" type="checkbox">自己出差 <input name="orderFor" id="orderFor-3" value="3" type="checkbox">家人或朋友 <input name="orderFor" id="orderFor-4" value="4" type="checkbox">同事 <input name="orderFor" id="orderFor-5" value="5" type="checkbox">代为客户预订 <input name="orderFor" id="orderFor-6" value="6" type="checkbox">没有预订过酒店 <span id="orderFor-error"> </span></div>
选择一个页面上的多个元素(控件):
选择 item5 ,item12,item13 下的所有的 checkbox ,注册 click 事件
$("#item5 > input:checkbox,
#item12 > input:checkbox,
#item13 > input:checkbox").click(checkBoxClickHandler);
// 当选择预定的次数是 1 次,变 checkbox 为单选。
function checkBoxClickHandler(){
// 获取name = “bookTimes” 的元素中被选中的那个元素的value 的值
times = $('input[@name=bookTimes][@checked]').val();
if(times == null || times != 2){
return;
}
// 取被点击的元素的父亲元素的id
var parentId = $(this).parent().attr("id");
// 取父亲元素下的所有的checkbox
checkboxs = $("#" + parentId + " > input:checkbox");
// 如果被单击的checkbox 没有被选中
if($(this).attr("checked") == false){
// 所有的checkbox 可选
checkboxs.removeAttr('disabled');
return;
}
// 除了被选中之外的所有checkbox 不可用,disabled
checkboxs.attr('disabled',true);
$(this).removeAttr('disabled');
}