所以我仔细阅读了类似的问题,但它们都有语法错误。我已经用可用的答案检查了我的代码,但它似乎不是语法错误;但我不断收到相同的“getElementById() 不是函数”错误。以下是相关代码片段。警报正在运行,因此可以在下拉菜单元素选项上适本地调用该函数。
$('.dropdown-menu a').on("click", "#1", function(e){
alert("hi");
getElementById("#caseReport").style.display = 'block';
});
<div class= "radioform" style='display:none;' id='caseReport'>
<h3>Please answer the following questions.</h3><br>
<form>
Previous Credible Reports in Humans:
<label class="radio-inline">
<input type="radio" name= "optradio1">Yes
</label>
<label class="radio-inline">
<input type="radio" name= "optradio1">No
</label>
<label class="radio-inline">
<input type="radio" name= "optradio1">Unsure
</label>
</form>
</div>
编辑:包括 ref 的下拉 div
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Evidence Type
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#" id= "1">Case Report</a></li>
</ul>
</div>
最佳答案
在指示它通过 ID 获取任何元素之前,您需要引用任何 DOM
位置,在这种情况下您可以简单地使用整个文档:
document.getElementById('caseReport');
请注意,在这种情况下不需要#
关于javascript - getElementById 不是显示元素的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45087277/