检查复选框时如何显示下拉列表?

时间:2016-09-20 04:55:47

标签: javascript php html

当我选中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>

1 个答案:

答案 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>