jquery html在单击事件时消失

jquery html在单击事件时消失,jquery,Jquery,请参阅以下代码: <body> <form id="form1" runat="server"> <div> <button id="helloButton"> Search</button> <div id="hello"> </div> <script type="text/javascript"> $(document).re

请参阅以下代码:

<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>

搜寻
$(文件)。准备好了吗(
函数(){
$('#helloButton')。单击(函数(){
$('#hello').html('hello world');
});
});


当我使用这个脚本时,它所做的只是闪现“hello world”,它不会将它保留在页面上。这与点击事件有关吗?我正在尝试单击按钮,然后将对象保留在页面上。

为了防止表单发布,以便您可以查看更改,您需要调用

$('helloButton')。单击(函数(e){
e、 预防默认值();
$('#hello').html('hello world');
});

否则,您可以简单地执行返回false,这将同时执行这两项操作 防止默认和停止传播

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

    $('#hello').html('<div>hello world</div>');
    return false;
});
$('helloButton')。单击(函数(e){
$('#hello').html('hello world');
返回false;
});

我复制粘贴了您的代码,但我不知道问题出在哪里。@reigel您没有粘贴表单标签,这就是为什么它没有在中提交jsfiddle@amosrivera-啊,是的!愚蠢的我…返回应该在函数的末尾吗?返回false之后的任何内容;不会到达也不会到达run@cfram54,谢谢你的编辑,我忘了…我今天还在度假,与编码失去了联系…我正在热身
$('#helloButton').click(function (e) {

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