dialog元素的showModal()方法演示页面
展示
代码
-
HTML:
<button class="button" onclick="dialog.showModal();">点击显示对话框</button> <dialog id="dialog"> <form id="form"> <p><input placeholder="请输入姓名" required /></p> </form> <form> <button class="button" form="form">确定</button> <button class="button normal" formmethod="dialog" value="cancel">取消</button> </form> </dialog>
-
JS:
form.addEventListener('submit', function (event) { event.preventDefault(); dialog.close('submit'); });