将显示设置为 none 从 DOM 中删除 svg 元素

Setting display to none remove the svg element from DOM

使用 jquery 或 javascript 将显示设置为 none 会删除 DOM 中的 svg 元素。这很奇怪。

我正在尝试使用 jquery 显示带有确定和取消按钮的弹出对话框,但在单击任何按钮后,它会从 DOM[=13= 中删除整个 svg 元素]

代码:

<div id="dialog" class="bs-example web_dialog">
    <form>
        <div class="form-group">
            <div class="col-lg-4" style="left: 173px; top: 258px; visibility: visible; position: absolute; overflow: visible; border: 1px solid #C5C5C5">
                <label for="inputEmail">Unique Id/Mobile Number:</label>
                <input type="number" class="form-control" id="inputEmail" placeholder="Unique Id" width="10px">
                <label for="inputPassword">Document URL</label>
                <input type="url" class="form-control" id="inputPassword" placeholder="URL">
                <br>
                <div class="btn-sm">
                    <button type="submit" id="btn_save" class="btn btn-primary btn-sm">Ok</button>
                    <button type="submit" id="btn_cancel" class="btn btn-primary btn-sm"  onclick="closePopUp(event)">Cancel</button>
                </div>
            </div>
        </div>
    </form>
</div>

<button type="submit" id="btn_cancel" class="btn btn-primary btn-sm"  onclick="closePopUp()">Cancel</button>

function closePopUp()
{
    document.getElementById('dialog').style.display = 'none';
}

执行上面的操作是从 DOM

中删除 svg 元素

按表单中的提交按钮是问题所在。即使表单元素具有表单属性的 none 个常用属性,按下提交按钮也会重新加载页面

选项 1:除非您正在提交数据,否则不要使用

选项 2:return 在提交按钮 onclick 中为 false

每次都选择选项 1 :p