选择一个单选按钮,其他文本框或下拉框disable掉

来源:互联网 发布:网络在线客服的要求 编辑:程序博客网 时间:2024/06/14 10:48

javascript

================================================================================================

//吸烟

$('input[id=boolean_smoking]').change(function(){ 

//是否吸烟,选择否(把烟龄、日吸烟量、是否戒烟disable掉)

if(this.value == '0'){
$('input[name=smokAge]').attr("disabled",true);
$('input[name=smokAge]').val("");
$('input[name=dailySmoking]').attr("disabled",true);
$('input[name=dailySmoking]').val("");
$('input[name=quitSmoking]').removeAttr("checked");
$('input[name=quitSmoking]').attr("disabled",true);
 
 
}if(this.value == '1'){
$('input[name=smokAge]').removeAttr("disabled");
$('input[name=dailySmoking]').removeAttr("disabled");
$('input[name=quitSmoking]').removeAttr("disabled");
}
});
//喝酒

 $('input[id=boolean_drinking]').change(function(){ 

//是否喝酒,选择否(把酒龄、饮酒频率、是否戒酒disable掉)

if(this.value == '0'){
$('input[name=drinkAge]').attr("disabled",true);
$('input[name=drinkAge]').val("");
$('input[name=quitDrinking]').attr("disabled",true);
$('input[name=quitDrinking]').removeAttr("checked");
$("#drinkingFrequency").val("");
$("#drinkingFrequency").attr("disabled",true);
 
}if(this.value == '1'){
$('input[name=drinkAge]').removeAttr("disabled");
$('input[name=quitDrinking]').removeAttr("disabled");
$("#drinkingFrequency").removeAttr("disabled");
}

});




jsp页面代码

================================================================================================

<div class="eat_right" style="font-size: 13px;">
<div class="item">
是否吸烟:

 <input name="smoking" id="boolean_smoking" type="radio" value="1" <c:if test="${healthdataStatic.smoking eq 1 }">checked="checked"</c:if>/>是&nbsp; 

<input  name="smoking" id="boolean_smoking" type="radio" value="0" <c:if test="${healthdataStatic.smoking eq 0 }">checked="checked"</c:if> />否
</div>
<div class="item">
<input type="hidden" name="id"  value="${healthdataStatic.id }">
烟&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄:
<input type="text" name="smokAge" class="smoker" value="${healthdataStatic.smokAge }"
style="width: 100px; height: 20px;" maxlength="3" <c:if test="${healthdataStatic.smoking eq 0 }">disabled="disabled"</c:if>/>&nbsp;年 &nbsp;&nbsp; 

<span id="smoker" style="color: red;"> </span>
</div>
<div class="item">
日吸烟量: 

<input type="text" name="dailySmoking" class="booder" value="${healthdataStatic.dailySmoking }" 

style="width: 100px; height: 20px;" maxlength="3"  <c:if test="${healthdataStatic.smoking eq 0 }">disabled="disabled"</c:if> />&nbsp;支 &nbsp;&nbsp; 

<span id="booder" style="color: red;"> </span>
</div>
<div class="item"><!-- 0320 -->
是否戒烟: 

<input name="quitSmoking" type="radio" value="1" <c:if test="${healthdataStatic.smoking eq 0 }">disabled="disabled"</c:if><c:if test="${healthdataStatic.quitSmoking eq 1 }">checked="checked"</c:if> />是&nbsp;
<input name="quitSmoking" type="radio" value="0" <c:if test="${healthdataStatic.smoking eq 0 }">disabled="disabled"</c:if><c:if test="${healthdataStatic.quitSmoking eq 0 && healthdataStatic.smoking eq 1 }">checked="checked"</c:if>/>否
</div>
</div>



<div class="eat_right" style="border-top: 1px solid #1d5a99; margin-top: 20px; font-size: 13px;">
<div class="item">
是否饮酒:

 <input name="drinking" id="boolean_drinking" type="radio" value="1" <c:if test="${healthdataStatic.drinking eq 1 }">checked="checked"</c:if>/>是&nbsp; 

<input name="drinking" id="boolean_drinking" type="radio" value="0" <c:if test="${healthdataStatic.drinking eq 0 }">checked="checked"</c:if>/>否
</div>
<div class="item">
酒&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄:

 <input type="text" name="drinkAge" class="a" value="${healthdataStatic.drinkAge }" 

style="width: 100px; height: 20px; margin-left:;" maxlength="3" <c:if test="${healthdataStatic.drinking eq 0 }">disabled="disabled"</c:if> />&nbsp;年 &nbsp;&nbsp; 

<span id="a" style="color: red;"> </span>
</div> 
<div class="item">
饮酒频率: 
<select name="drinkingFrequency" id="drinkingFrequency" style="width: 105px" <c:if test="${healthdataStatic.drinking eq 0 }">disabled="disabled"</c:if>>
                      <option value="" ></option>
                      <option value="偶尔饮酒" <c:if test="${healthdataStatic.drinkingFrequency == '偶尔饮酒'}">selected="selected"</c:if>>偶尔饮酒</option>
                      <option value="每周1-2次 " <c:if test="${healthdataStatic.drinkingFrequency == '每周1-2次'}">selected="selected"</c:if>>每周1-2次 </option>
                      <option value="每周3次以上" <c:if test="${healthdataStatic.drinkingFrequency == '每周3次以上'}">selected="selected"</c:if>>每周3次以上</option> 
                      <option value="每周醉酒" <c:if test="${healthdataStatic.drinkingFrequency == '每周醉酒'}">selected="selected"</c:if>>每周醉酒</option>
 </select>
</div>
<div class="item"><!-- 0320 -->
是否戒酒: 

<input name="quitDrinking" type="radio" value="1" <c:if test="${healthdataStatic.drinking eq 0 }">disabled="disabled"</c:if><c:if test="${healthdataStatic.quitDrinking eq 1 }">checked="checked"</c:if>/>是&nbsp;
<input name="quitDrinking" type="radio" value="0" <c:if test="${healthdataStatic.drinking eq 0 }">disabled="disabled"</c:if><c:if test="${healthdataStatic.quitDrinking eq 0 && healthdataStatic.drinking eq 1}">checked="checked"</c:if>/>否
</div>
</div>

0 0
原创粉丝点击