繁体   English   中英

单击按钮后,jQuery切换快速消失

[英]jquery toggle disappear quickly after clicking button

这是我的代码。

<div id="hint-toggle" class="ui-body ui-body-e" style="display: none">
   <p>No Hints available right now,check it later</p>
</div>

<button id="show-hint" onclick="showHint();"type="submit" data-inline="true" data-theme="c">Show Hint</button>

<script type="text/javascript">
    function showHint(event){
    $("#hint-toggle").toggle();
        }
</script>

单击show hint按钮后,它会出现,但在2秒钟之内会消失..我是否错过了代码中的任何内容? 请帮助我。我想显示hint-toggle直到我再次按show hint按钮。

仅供参考: http : //jsfiddle.net/shreeramns/rUKbh/

为了防止“提交”按钮采取其默认操作,您应阻止该默认操作:

<button id="show-hint" onclick="showHint(event);" type="submit" data-inline="true" data-theme="c">Show Hint</button>

注意我们如何在JS中传递event对象

function showHint(event) {
    event.preventDefault();
    $("#hint-toggle").toggle();
}   

演示: http//jsfiddle.net/DDsZn/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM