jquery - 使用查询将 HTML div 设置为可见

标签 jquery html hidden visible

我在 View 中有以下 div:

<div id=someMessage> Some message </div>

我想保持隐藏状态,直到 jquery 脚本发现条件为真并将其更改为可见:

//in this specific case there are 12 items
if (items > 10) 
{
 $('#someMessage'). (I don't know what to do here, is it best to use html's disabled attribute?)
}

如果有人能提供帮助,我将非常感激。谢谢

最佳答案

设置div默认隐藏:

<div id=someMessage style="display:none"> Some message </div>

然后,使用 jQuery 的 show() 方法显示它:

//in this specific case there are 12 items
if (items > 10) 
{
 $('#someMessage').show();
}

关于jquery - 使用查询将 HTML div 设置为可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24350805/

相关文章:

javascript - document.style.display 由于某种原因不粘

jQuery - 你能检查一个类是否有另一个类吗?

javascript - JQuery 在执行下一行代码之前等待几秒钟

javascript - Jquery clickevent 不工作

javascript - Vue2 : view-router exception when trying to use <router-view>

jquery - 使用 div 作为与其他内容重叠的下拉菜单?

java - Play 2.0 生成没有 div 包装器的隐藏字段

javascript - 选择伪元素 :focus and :active via JS

javascript - 等到 HTML 元素得到一个类然后做一些事情

javascript - 当点击列表项时隐藏其他元素