【发布时间】:2020-05-05 17:04:10
【问题描述】:
很抱歉这个问题,但我似乎无法弄清楚。我试图在页面加载时隐藏“#postcodeConf”元素,但它就是不这样做!我把代码放在 JSfiddle 中,它按预期工作!
我做错了什么?!
<html>
<head>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script>
$("#postcodeConf").hide();
</script>
</head>
<body>
<input type="text" id="postcodeEntry">
<button onclick="myFunction()">Search</button>
<p id="postcodeConf">Postcode Ok</p>
</body>
</html>
【问题讨论】:
-
问题是
$("#postcodeConf").hide();在 html 中创建元素之前运行。用$(document).ready(function() {})包装你的代码
标签: javascript html jquery