jQuery HTML在单击事件中消失 [英] jquery html disappears on click event

查看:117
本文介绍了jQuery HTML在单击事件中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见以下代码:

<body>
<form id="form1" runat="server">
<div>

    <button id="helloButton">
        Search</button>
    <div id="hello">


    </div>
    <script type="text/javascript">
        $(document).ready(
        function () {

            $('#helloButton').click(function () {


                $('#hello').html('<div>hello world</div>');

            });

        });
    </script>
</div>
</form>

当我使用此脚本时,它所做的只是flash"hello world",它不会保留在页面上.这与点击事件有关吗?我试图单击该按钮,然后将对象保留在页面上.

When I use this script, all it does is flash "hello world", it doesn't keep it on the page. Does this has something to do with the click event? I'm trying to click the button and then leave the object on the page.

推荐答案

否则,您只需执行return false即可 preventDefault并停止传播

Otherwise you can simply do a return false which will do both preventDefault and stop propagation

$('#helloButton').click(function (e) {

    $('#hello').html('<div>hello world</div>');
    return false;
});

这篇关于jQuery HTML在单击事件中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆