添加元素并使用IE删除它们

时间:2017-09-12 21:17:53

标签: javascript jquery asp.net-mvc internet-explorer

我有一个页面,我可以在其中添加多行来表示IP地址,Chrome中的一切正常,但我注意到我无法删除已添加的新行。如果行从头开始就可以了。这只发生在IE上。

我的网页代码如下:

@section Scripts
{
    <script>
        jQuery(document).ready(function ($) {
            $('#add-room').on('click', function () {
                jQuery.get('/MyWebUi/Groups/AddAuthorizedClient').done(function (html) {
                    $('#rooms-list').append(html);
                });
            });
        });

        function DeleteRow(id) {
            var element = document.getElementById("AuthClientId" + id);
            element.parentElement.removeChild(element);
            //document.getElementById("AuthClientId" + id).remove();
        };
    </script>
}

<h2>Group</h2>

@using (Html.BeginForm("Save", "Groups"))
{
    @Html.EditorFor(x => x)
    @Html.HiddenFor(x => x.Id)

    <h4>Authorized clients</h4>
    <div id="rooms-list">
        @Html.EditorForMany(x => x.AuthorizedClients, x => x.Index)
    </div>

    <input type="button" class="btn btn-default" id="add-room" value="Add client" />
    <button type="submit" class="btn btn-primary">Save</button>
}

第一个函数调用此方法:

    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    public ActionResult AddAuthorizedClient()
    {
        var building = new Group();
        building.AuthorizedClients.Add(new ModelAbstraction.AuthorizedClient() { Id = Guid.NewGuid() });

        return View(building);
    }

我的AuthorizedClient编辑器模板如下:

<div class="editorRow" id=@string.Concat("AuthClientId", Model.Id.ToString())>
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="form-group">
                @Html.LabelFor(x => x.IpAddress, new { title = ModelMetadata.FromLambdaExpression(x => x.IpAddress, ViewData).Description })
                @Html.TextBoxFor(x => x.IpAddress, new { @class = "form-control" })
                @Html.ValidationMessageFor(x => x.IpAddress)
            </div>

            @Html.HiddenFor(x => x.Id)
            <input type="button" class="btn btn-danger" id="delete-client" value="Delete client" onclick="DeleteRow(&quot;@Model.Id.ToString()&quot;)"/>
        </div>
    </div>
</div>

我认为问题可能是在IE中我没有在调试器中看到(单击Add后新创建的html),显示在DOM Explorer窗口中而不是在调试器中...并且删除方法不是显然被称为

0 个答案:

没有答案
相关问题