2016-09-20 58 views
0

當我檢查HTMLJavaScript中的複選框時,如何顯示包含動態內容的下拉列表?我已經嘗試了一些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'))?>">&nbsp;&nbsp;Select Month</option> 
    <option value="January" <?=($this->input->post('month') == 'January')?'selected':''?>>&nbsp;&nbsp;January</option> 
    <option value="February" <?=($this->input->post('month') == 'February')?'selected':''?>>&nbsp;&nbsp;February</option> 
    <option value="March" <?=($this->input->post('month') == 'March')?'selected':''?>>&nbsp;&nbsp;March</option> 
    <option value="April" <?=($this->input->post('month') == 'April')?'selected':''?>>&nbsp;&nbsp;April</option> 
    <option value="May" <?=($this->input->post('month') == 'May')?'selected':''?>>&nbsp;&nbsp; 
    May</option> 
    <option value="June" <?=($this->input->post('month') == 'June')?'selected':''?>>&nbsp;&nbsp; 
    June</option> 
    <option value="July" <?=($this->input->post('month') == 'July')?'selected':''?>>&nbsp;&nbsp; 
    July</option> 
    <option value="August" <?=($this->input->post('month') == 'August')?'selected':''?>>&nbsp;&nbsp;August</option> 
    <option value="September" <?=($this->input->post('month') == 'September')?'selected':''?>>&nbsp;&nbsp;September</option> 
    <option value="October" <?=($this->input->post('month') == 'October')?'selected':''?>>&nbsp;&nbsp;October</option> 
    <option value="November" <?=($this->input->post('month') == 'November')?'selected':''?>>&nbsp;&nbsp;November</option> 
    <option value="December" <?=($this->input->post('month') == 'December')?'selected':''?>>&nbsp;&nbsp;December</option> 
</select> 

回答

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>