我在HTML中有一个复选框:
<div class="checkbox">
<label>
<input type="checkbox"> Want to choose another picture?
</label>
</div>
我还有一个文件选择器,用户可以选择并上传文件:
<div class="form-group">
<label for="exampleInputFile">Choose main image</label>
<input type="file" id="exampleInputFile">
<p class="help-block">This will be your thumbnail image</p>
</div>
如果选中了第一个复选框,我该如何才显示文件选择器?
由于
答案 0 :(得分:0)
希望这有帮助
<div class="checkbox">
<label>
<input type="checkbox" id="chk"> Want to choose another picture?
</label>
</div>
<div class="form-group" id="file-input" style="display:none;">
<label for="exampleInputFile">Choose main image</label>
<input type="file" id="exampleInputFile">
<p class="help-block">This will be your thumbnail image</p>
</div>
<script>
document.getElementById('chk').onchange = function(){
if(this.checked) {document.getElementById('file-input').style.display='block';
//more js statements
}
else {document.getElementById('file-input').style.display='none';
//more js statements
}
}
</script>