gpt4 book ai didi

javascript - jquery 不显示隐藏元素

转载 作者:太空宇宙 更新时间:2023-11-04 04:12:14 25 4
gpt4 key购买 nike

我的 html 中有这两个元素

<p id="fullday" hidden="true" >Full Day</p>
<input type="checkbox" id="fullday" hidden="true" name="CheckIn">

当我调用函数时在我的js文件中

$('#fullday').show();

只有<p>显示元素并且复选框仍然隐藏..提前谢谢

最佳答案

这里有 2 个问题。

  1. ID 必须是唯一的

    改为使用类,类可用于多个元素以标识一组元素。

  2. hidden="none" 是一种隐藏您想要显示的值的非标准方式。来自 MDN 的使用建议

    This attribute must not be used to hide content that could be legitimately be shown. For example, it shouldn't be used to hide tabs panels of a tabbed interface, as this is a styling decision and another style showing them would lead to a perfectly correct page.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#hidden

    使用 display:none 代替,如下所示,或者使用 CSS 隐藏。

    <p class="fullday" style="display:none" >Full Day</p>
    <input type="checkbox" class="fullday" style="display:none" name="CheckIn">

    那么js就是了

    $(".fullday").show();

关于javascript - jquery 不显示隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20505199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com