【问题标题】:One Change to JQuery Toggle Code: Content is showing before click. How do I make the content appear AFTER clicking the button in this code?对 JQuery 切换代码的​​一项更改:内容在单击之前显示。单击此代码中的按钮后,如何使内容显示?
【发布时间】:2012-12-16 04:04:26
【问题描述】:
<!DOCTYPE html>
<html>
<head>
  <style>
p { margin:-3px 0px 0px 3px;
background:#212121;
width:175px;
padding:10px;
color:#fff;
font-weight:500;
font-size:14px; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button>Toggle 'em</button>

<p>I figured out how to get the toggle to look and work up to this point, but I can't seem to get this content box to appear ONLY AFTER the button is clicked upon NOT before. And, when the visitor doesn't want to see the content anymore, s/he would have to click on the button (toggling). If you happen to know how to incorporate a delayed auto close on this toggle, please do tell (if not, no biggie--not my main focus). Thanks! </p>
    <script>
$("button").click(function () {
$("p").toggle("fast");
});    
</script>

</body>
</html>

我对 JQuery 了解不多,但我使用了这个网站 http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_toggle 并想出了如何让切换器看起来和工作到这一点,但我似乎无法让这个内容框出现仅在单击按钮之后,而不是之前。而且,当访问者不想再看到内容时,他/她必须单击按钮(切换)。如果您碰巧知道如何在此切换中加入延迟自动关闭,请务必告诉(如果没有,没什么大不了的——不是我的主要关注点)。谢谢!

【问题讨论】:

  • 嘿伙计,看看我的回答,有解决办法!

标签: jquery


【解决方案1】:

改用这个!

$(document).ready( function() {
$("p").hide();
$("button").click(function () {
$("p").toggle("fast");
});
});

http://jsfiddle.net/N6NJR/

【讨论】:

    【解决方案2】:

    只需添加:

    显示:无;

    到 CSS

    【讨论】:

    • 哦!我首先看到了你上面的答案并尝试了它。无论如何,感谢 mil 这么快的响应。
    • 如果可能,最好使用 CSS 而不是 Javascript。
    猜你喜欢
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    相关资源
    最近更新 更多