我对 jQuery 很陌生,所以如果这听起来很愚蠢,请不要跳我。我想知道是否有一种方法可以选择其中的“#ammountbest2”、“input”和“textarea”,这样我就可以使用一个选择器一次隐藏和清除其中的值,所以我不会必须拼出每一个。像兄弟姐妹或父母之类的东西。有了它,我可以在最后附上:“.val('').css('display', none')”
$('#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>