表單上有一組或多組單選按鈕。該值可能以^的值開始。一旦選擇了另一個值,^不再可行,因此div需要隱藏。這裏是源和HTML,用的jsfiddle鏈接到它一起:http://jsfiddle.net/RSNxS/使用jQuery刪除單選按鈕
$(function(){
$('.tristateRadio').bind("change", handleTristateRadioChange);
function handleTristateRadioChange(e) {
var button = $this;
var id = button.id();
$("#"+id).filter(
function(){ this.value == "^"}
).parent().hide();
}
});
HTML
$<div class="questionItem">
<h3>C0900A</h3>
Staff asmt mental status: recall current season <br/>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_12__Answer" name="answers[12].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_12__Answer" name="answers[12].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_12__Answer" name="answers[12].Answer" type="radio" value="-" /> (-) Not assessed</div>
<div class="questionCheckbox"><input checked="checked" class="tristateRadio" id="answers_12__Answer" name="answers[12].Answer" type="radio" value="^" /> (^) Blank (skip pattern)</div>
</div>
<div class="questionItem">
<h3>C0900B</h3>
Staff asmt mental status: recall location of room <br/>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_13__Answer" name="answers[13].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_13__Answer" name="answers[13].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_13__Answer" name="answers[13].Answer" type="radio" value="-" /> (-) Not assessed</div>
<div class="questionCheckbox"><input checked="checked" class="tristateRadio" id="answers_13__Answer" name="answers[13].Answer" type="radio" value="^" /> (^) Blank (skip pattern)</div>
</div>
<div class="questionItem">
<h3>C0900C</h3>
Staff asmt mental status: recall staff names/faces <br/>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_14__Answer" name="answers[14].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_14__Answer" name="answers[14].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_14__Answer" name="answers[14].Answer" type="radio" value="-" /> (-) Not assessed</div>
<div class="questionCheckbox"><input checked="checked" class="tristateRadio" id="answers_14__Answer" name="answers[14].Answer" type="radio" value="^" /> (^) Blank (skip pattern)</div>
</div>
<div class="questionItem">
<h3>C0900D</h3>
Staff asmt mental status: recall in nursing home <br/>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_15__Answer" name="answers[15].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_15__Answer" name="answers[15].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_15__Answer" name="answers[15].Answer" type="radio" value="-" /> (-) Not assessed</div>
<div class="questionCheckbox"><input checked="checked" class="tristateRadio" id="answers_15__Answer" name="answers[15].Answer" type="radio" value="^" /> (^) Blank (skip pattern)</div>
</div>
<div class="questionItem">
<h3>C0900Z</h3>
Staff asmt mental status: none of above recalled <br/>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_16__Answer" name="answers[16].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_16__Answer" name="answers[16].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
<div class="questionCheckbox"><input class="tristateRadio" id="answers_16__Answer" name="answers[16].Answer" type="radio" value="-" /> (-) Not assessed</div>
<div class="questionCheckbox"><input checked="checked" class="tristateRadio" id="answers_16__Answer" name="answers[16].Answer" type="radio" value="^" /> (^) Blank (skip pattern)</div>
</div>
你介意在jsfiddle.net上發帖嗎? – hafichuk
這和你最後一個問題不一樣嗎? (http://stackoverflow.com/questions/11005071/removing-a-option-from-dropdownlist-item-with-jquery) – Nope
您的HTML無效,您有多個重複的id元素,id屬性應始終是唯一的。除此之外,請清楚你的問題,很難理解,我很樂意幫助你,歡呼! –