gpt4 book ai didi

javascript - .show() 和 .hide() 在 jquery 中如何工作

转载 作者:行者123 更新时间:2023-11-28 15:15:38 27 4
gpt4 key购买 nike

我目前正在进行注册,根据注册过程中的位置,我隐藏和显示不同的输入。目前,我有 4 个输入,我想从隐藏其中两个开始。我知道在 jquery 中你可以使用 .hide() 来做到这一点。但是,当我加载页面时,两个输入出现然后消失。 .show() 和 .hide() 对元素做了什么?它会改变显示吗?如何才能使页面加载时元素开始隐藏,然后在需要时可以调用 .show() ?

我现在的代码如下。我想要的是我不必在ready函数中调用.hide()并且元素开始隐藏。

$(document).ready(function ()
{
//loads elements then hides them
$("#input3").hide();
$("#input4").hide();

//some time later when triggers are set and I want to show the inputs
$("#input3").show();
$("#input4").show();
}

我想要什么:

$(document).ready(function ()
{
//inputs 3 and 4 are already hidden

//some time later when triggers are set and I want to show the inputs
$("#input3").show();
$("#input4").show();
}

最佳答案

将“不显示”添加到您的 html 元素

<input type="text" id="input1" style="display: none" />

或者使用CSS

#input1, #input2 {
display: none;
}

关于javascript - .show() 和 .hide() 在 jquery 中如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34104958/

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