简体   繁体   English

为什么第二份表格在提交后消失了?

[英]Why does the second form disappear after submiting?

There is the piece of code containing 2 forms: 有一段代码包含两种形式:

<form class="emp-delete">
    <label for="emp-id">Id:</label>
    <input type="text" id="emp-id" />
    <input type="submit" id="submit" value="delete" />
    <span id="status" />
</form>
<script type="text/javascript">
    $("#submit").click(function(){
            $.ajax({
            type: "DELETE",
            url: "/corporate/employees/" + $("#emp-id").val(),
            complete: function(r){
                    $("#status").text(r.responseText);
                }
            })
            return false;
        })
</script>
<p><spring:message code="createEmployee.title"/>
<form class="emp-create">
    <label for="name" />
    <input type="text" id="name" value="create"/>
    <input type="submit" id="add-emp" />
</form>
<script type="text/javascript">
    $("#add-emp").click(function(){
        var employeeObject= { name: $("#name").val() }
        $.ajax({
            type: "POST",
            data: JSON.stringify(employeeObject),
            contentType: "application/json",
            url: "/corporate/employees"
        })
        return false;
    })
</script>

The issue is after clicking the delete button the second form dissapears. 问题是单击delete按钮后,第二个表单消失了。

Before : 之前

在此处输入图片说明

After : 之后

在此处输入图片说明

How can I do that the second form doesn't dissapear when clicking the delete button. 单击delete按钮时,第二种形式不消失。

UPDATE 更新

DEMO 演示

The problem is right here: 问题就在这里:

<span id="status"/>

Change this to: 更改为:

<span id="status"></span>

The browser thinks, that the span is openend and your second form is a child of it, which got replaced with your text. 浏览器认为该范围是openend,而您的第二个表单是它的子级,已被您的文本替换。

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

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