当我选中HTML
和JavaScript
中的复选框时,如何显示包含动态内容的下拉菜单?我尝试了一些JavaScript
内容,因为我是编码的初学者,希望我的测试代码不需要在这里。或者我可以使用除通常JavaScript
之外的任何其他方法吗?
<select id="month" name="month" class="input-text" value="<?=set_value('month',$this->input->post('month'))?>">
<option value="<?=set_value('month',$this->input->post('month'))?>"> Select Month</option>
<option value="January" <?=($this->input->post('month') == 'January')?'selected':''?>> January</option>
<option value="February" <?=($this->input->post('month') == 'February')?'selected':''?>> February</option>
<option value="March" <?=($this->input->post('month') == 'March')?'selected':''?>> March</option>
<option value="April" <?=($this->input->post('month') == 'April')?'selected':''?>> April</option>
<option value="May" <?=($this->input->post('month') == 'May')?'selected':''?>>
May</option>
<option value="June" <?=($this->input->post('month') == 'June')?'selected':''?>>
June</option>
<option value="July" <?=($this->input->post('month') == 'July')?'selected':''?>>
July</option>
<option value="August" <?=($this->input->post('month') == 'August')?'selected':''?>> August</option>
<option value="September" <?=($this->input->post('month') == 'September')?'selected':''?>> September</option>
<option value="October" <?=($this->input->post('month') == 'October')?'selected':''?>> October</option>
<option value="November" <?=($this->input->post('month') == 'November')?'selected':''?>> November</option>
<option value="December" <?=($this->input->post('month') == 'December')?'selected':''?>> December</option>
</select>
答案 0 :(得分:0)
在用户选中复选框时尝试一次示例然后选择框将以隐藏模式显示。
function checkfun(){
if(document.getElementById('check').checked == true){
document.getElementById('select').innerHTML="<select style=\"width:150px;\"><option></option><option>1</option></select>";
}
else{
document.getElementById('select').innerHTML =" ";
}
}
<p><input type="checkbox" id="check" onchange="checkfun()"/><span id="select"></span></p>