admin管理员组文章数量:1333158
At first, I get a dialog in my html
<dialog open>
<button id="close">Close</button>
</dialog>
And then, I need a JS function to close or hide it.
How to do it ?
Also i have a submit button to show the dialog. How to show it ?
<input type="Submit" value="Submit" id="show" />
At first, I get a dialog in my html
<dialog open>
<button id="close">Close</button>
</dialog>
And then, I need a JS function to close or hide it.
How to do it ?
Also i have a submit button to show the dialog. How to show it ?
<input type="Submit" value="Submit" id="show" />
Share
Improve this question
edited Jan 7, 2019 at 11:06
Nuno Cruces
1,77317 silver badges18 bronze badges
asked Nov 13, 2013 at 15:43
user2988394user2988394
892 silver badges6 bronze badges
2
- The <dialog> tag is currently only supported in Chrome, and Safari 6. so in which browser you are working? – Anand Jha Commented Nov 13, 2013 at 15:53
- why don't you use costume dialog rather using HTML5-dialog, because most of the browser doesn't support it. – Anand Jha Commented Nov 13, 2013 at 16:33
2 Answers
Reset to default 4Try this,
<dialog id="dialog">
<p>Hi, I'm a dialog!</p>
<button id="close">Okay</button>
</dialog>
<button id="show">Show Dialog</button>
JS script
var dialog = document.getElementById('dialog');
var showBtn = document.getElementById('show');
var closeBtn = document.getElementById('close');
// Setup an event listener for the show button.
showBtn.addEventListener('click', function(e) {
e.preventDefault();
// Show the dialog.
dialog.show();
});
// Setup an event listener for the close button.
closeBtn.addEventListener('click', function(e) {
e.preventDefault();
// Close the dialog.
dialog.close();
});
for more details see http://blog.teamtreehouse./a-preview-of-the-new-dialog-element
The documentation draft for the <dialog>
HTML5 tag is available here: http://www.w3/html/wg/drafts/html/master/interactive-elements.html#the-dialog-element
Basically you can use the show()
and close()
methods to interact with the dialog.
Check this tutorial for an example: http://blog.teamtreehouse./a-preview-of-the-new-dialog-element
Make sure that you enabled this feature in Chrome:
Once you have Chrome Canary installed go to chrome://flags and enable the Enable experimental Web Platform features flag. You will need to restart the browser for the change to take effect.
本文标签: javascriptHow to close the Html5 dialogStack Overflow
版权声明:本文标题:javascript - How to close the Html5 dialog - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351474a2458580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论