我對jQuery很新,所以如果這聽起來很愚蠢,請不要跳我。我想知道是否有辦法在裏面選擇「#ammountbest2」,「輸入」和「textarea」,這樣我就可以一次隱藏和清除所有值,只用一個選擇器,所以我不會必須說明每一個。像兄弟姐妹或父母一樣。隨着我可以只重視結尾:」 .VAL(‘’)。CSS(‘顯示’,沒有')」選擇幾個元素jQuery
$('#ammountbest').change(function() {
var ammountbest = ""
$('#ammountbest option:selected').each(function() {
ammountbest += $(this).text() + "";});
if(ammountbest == "0") {$('#ammountbest1,#ammountbest2').css('display', 'none');}
if(ammountbest == "1") {
$('#ammountbest1').css('display', 'block');
$('#ammountbest2 input,#ammountbest2 textarea').val('');
$('#ammountbest2').css('display', 'none');
}
if(ammountbest == "2") {
$('#ammountbest1,#ammountbest2').css('display', 'block');
}
})
.trigger('change');
<select id="ammountbest">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
<!-- 1 Winners -->
<div id="ammountbest1" style="display:none;">
<label for="besttitle1" title="Title">Title 01:</label><br>
<input name="besttitle1" id="besttitle1" size="30" type="input">
<label for="bestschool1" title="School">School 01:</label><br>
<input name="bestschool1" id="bestschool1" size="30" type="input">
<label for="bestvideo1" title="Video">Video Embed Code 01:</label><br>
<textarea name="bestvideo1" id="bestvideo1" cols="30" rows="5"></textarea>
</div>
<!-- 2 Winners -->
<div id="ammountbest2" style="display:none;">
<label for="besttitle2" title="Title">Title 02:</label><br>
<input name="besttitle2" id="besttitle2" size="30" type="input">
<label for="bestschool2" title="School">School 02:</label><br>
<input name="bestschool2" id="bestschool2" size="30" type="input">
<label for="bestvideo2" title="Video">Video Embed Code 02:</label><br>
<textarea name="bestvideo2" id="bestvideo2" cols="30" rows="5"></textarea>
</div>
你想要'#amountbest2'元素以及'input'和'textarea'嗎? – 2012-08-10 21:44:49
是的,我想一次選擇div中的所有元素。 – 2012-08-10 21:47:09