【问题标题】:Basic Jquery Question - hiding an element [duplicate]基本的Jquery问题 - 隐藏一个元素[重复]
【发布时间】: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>

【问题讨论】:

标签: javascript html jquery


【解决方案1】:
    <input type="text" id="postcodeEntry">
     <button onclick="myFunction()">Search</button>
     <p id="postcodeConf">Postcode Ok</p>  

    <script>
     $("#postcodeConf").hide();
    </script>

按照以下顺序添加,因为dom元素只有在渲染后才能被捕获。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2015-03-01
    相关资源
    最近更新 更多