選中Id爲form-group-radio 下,而且class是radio-inline btn btn-default center-block的標籤並執行每一個function內容css
$("#form-group-radio .radio-inline.btn.btn-default.center-block").each(function(){ //執行內容 }
<div id = "form-group-radio" class="form-group"> <div class="col-sm-offset-1 col-sm-5"> <h4> <label class="radio-inline btn btn-default center-block" onclick="radioSimulation('radioPass');"> <strong>合格</strong> </label> <input id = "radioPass" type="radio" name="inlineRadioOptions" style="display:none" value="Pass"> </h4> </div> <div class="col-sm-5"> <h4> <label class="radio-inline btn btn-default center-block" onclick="radioSimulation('radioFail');"> <strong>不合格</strong> </label> <input id = "radioFail" type="radio" name="inlineRadioOptions" style="display:none" value="Fail"> </h4> </div> </div>
//模仿radio選項方法 function radioSimulation(avtive){ $("#" + avtive).prop("checked",true); //顯示Error輸入框 if ($("#" + avtive).val() == "Fail"){ $("#form-group-select").show(); }else{ $("#form-group-select").hide(); } $("#form-group-radio .radio-inline.btn.btn-default.center-block").each(function(){ var next = $(this).next(); //顯示修改選中的背景樣式 if (next.attr("checked")){ $(this).css("background-color","#4a86e8"); }else{ $(this).css("background-color","#fff"); } }) }
根據當前已查詢出來的節點選擇附近的節點html
$(this).parent()
$(this).parents()
$(this).children()
$(this).contents()
$(this).prev()
$(this).prevAll()
$(this).next()
$(this).nextAll()
$(this).siblings()
$(this).find("span")
控件經常使用判斷操做ide
$("#radio").prop("checked",true)
if ($("#radio").attr("checked")){ //執行選中結果 }else{ //執行未選中結果 }
$("#btn").css("background-color","#00FF00");