【发布时间】:2016-03-10 08:48:14
【问题描述】:
我目前正在注册,我根据注册过程中的位置隐藏和显示不同的输入。目前,我有 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();
}
【问题讨论】:
标签: javascript jquery