代码如下:
<form class="navbar-form navbar-left">
<div class="form-group">
<button class="search-btn" style="border-radius: 40px; margin-top: 6px; border: #ffffff00;
background-color: #46555f00;" data-placement="left">
<span class="glyphicon glyphicon-search" style="font-size: 90%;"></span>
</button>
<div id="inpDiv" style="margin: -15% 20%;">
<input type="text" class="form-control" placeholder="Search" onkeydown="entersearch()"
style="background-color: #bfcbd9dc; display: none; float: left;">
</div>
</div>
<script>
var fom = document.getElementsByTagName("form")[0];
var But = fom.getElementsByTagName("button")[0];
var Inp = fom.getElementsByTagName("input")[0];
var divInp = document.getElementById("inpDiv");
But.onclick = function (e) { //点击出现
Inp.style.display = "block";
e.stopPropagation(); //阻止冒泡
}
// 点击空白消失
document.onclick = function (e) {
Inp.style.display = "none";
}
divInp.onclick = function (e) {
e = e || event;
stopFunc(e);
}
function stopFunc(e) {
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
}
</script>
</form>
你的错误截图是jQuery文件上的 应该是你用错了方法什么的