Jquery 取值相关

/* ("${feed.eleclean}"=="1") ? $("#cg1").hide() : $("#cg1").show();
("${feed.elelight}"=="1") ? $("#cg2").hide() : $("#cg2").show();
("${feed.opendoor}"=="1") ? $("#cg3").hide() : $("#cg3").show();
("${feed.elelayer}"=="1") ? $("#cg4").hide() : $("#cg4").show();
("${feed.elebottom}"=="1") ? $("#cg5").hide() : $("#cg5").show();
("${feed.eleruncondition}"=="1") ? $("#cg6").hide() : $("#cg6").show(); */

/***第一种方法 直接通过三目运算取到input的value值 进行隐藏和显示   好low 。。。  三目运算不要if 不要if  不要if***/


$('input:radio:checked').each(function() {
var rad=$(this).parent().parent('.control-group');
if($(this).val()=="1"){
$(rad).hide();
}

/***第二种方法  获取所有被选中的radion  ,找到其父类元素

 获取所有被选中的radion  $('input:radio:checked')

通过当前选中值 找到他的父类元素  $(this).parent().parent('.control-group');

***/


/* var radd=$(this).attr("data-cg");
if($(this).val()=="1"){
$("#"+radd).hide();
} */
});

/***第三种种方法  通过给input标签 自定义属性 与父级元素id同名

 判断当前选中的radio 的value 是否为1    

重点 这里$(this).val()调用jquery的方法 而不是 value

***/

<div class="control-group" id="cg1" >
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢环境卫生是否良好:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name="eleclean" id="eleclean" value="1" disabled="disabled"/>是
<input type="radio" name="eleclean" id="eleclean" value="0" disabled="disabled"/>否
</div>
</div>
<div class="control-group" id="cg1">
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢照明是否正常:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name=elelight id="elelight" value="1" disabled="disabled"/>是
<input type="radio" name="elelight" id=elelight value="0" disabled="disabled"/>否
</div>
</div>
<div class="control-group" id="cg1">
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢开关门是否正常:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name="opendoor" id="opendoor" value="1" disabled="disabled"/>是
<input type="radio" name="opendoor" id="opendoor" value="0" disabled="disabled"/>否
</div>
</div>
<div class="control-group" id="cg1">
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢平层度是否正常:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name="elelayer" id="elelayer" value="1" disabled="disabled"/>是
<input type="radio" name="elelayer" id="elelayer" value="0" disabled="disabled"/>否
</div>
</div>
<div class="control-group" id="cg1">
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢按钮是否正常:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name="elebottom" id="elebottom" value="1" disabled="disabled"/>是
<input type="radio" name="elebottom" id="elebottom" value="0" disabled="disabled"/>否
</div>
</div>
<div class="control-group" id="cg1">
<label class="control-label col-md-2 col-sm-2 col-xs-12" >轿厢运行过程是否正常:</label>
<div class="form-control required" style="float: left;">
<input type="radio" name="eleruncondition" id="eleruncondition" value="1" disabled="disabled"/>是
<input type="radio" name="eleruncondition" id="eleruncondition" value="0" disabled="disabled"/>否
</div>
</div>

原文地址:https://www.cnblogs.com/xkoko/p/6549700.html