• 主页
  • HTML5对话框元素关闭按钮不能正常工作

HTML5对话框元素关闭按钮不能正常工作

我正在研究这个问题post,在我的代码中应用它时遇到了问题。

这让我感到困惑,因为我对保存按钮所做的操作与对取消按钮所做的操作完全相同(至少在关闭按钮时是这样),而且单击取消按钮后什么也不会发生。

<dialog class="my-modal"> 
                <p>Add Cust</p>
                <label for="nameField">Name</label><input id=nameField><br>
                <label for="addressField">Address</label><input id=addressField><br>
                <label for="cityField">City</label><input id=cityField><br>
                <label for="stateField">State</label><input id=stateField size=2> &nbsp;
                <label for="zipField">Zip</label><input id=zipField><br>

                <br>
                <button onclick="closeAndSave()">Save</button>
                <button onclick="close()">cancel</button>
            </dialog>
function close(){
    const modal = document.querySelector('.my-modal');
    modal.close();
}

我也尝试过:

<button class="btn btn-default" data-dismiss="my-modal" aria-label="Close">Cancel</button>

转载请注明出处:http://www.jxbyjx.net/article/20230526/1398526.html