aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmldialogelement
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/htmldialogelement
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/htmldialogelement')
-rw-r--r--files/zh-cn/web/api/htmldialogelement/index.html247
-rw-r--r--files/zh-cn/web/api/htmldialogelement/show/index.html113
2 files changed, 360 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/htmldialogelement/index.html b/files/zh-cn/web/api/htmldialogelement/index.html
new file mode 100644
index 0000000000..95a1784e3a
--- /dev/null
+++ b/files/zh-cn/web/api/htmldialogelement/index.html
@@ -0,0 +1,247 @@
+---
+title: HTMLDialogElement
+slug: Web/API/HTMLDialogElement
+tags:
+ - API
+ - HTML DOM
+ - Interface
+ - Reference
+translation_of: Web/API/HTMLDialogElement
+---
+<div>{{ APIRef("HTML DOM") }}</div>
+
+<p>{{ SeeCompatTable() }}</p>
+
+<p><strong><code>HTMLDialogElement</code></strong>接口提供操作{{HTMLElement("dialog")}} 元素的方法.。此接口的方法和属性继承自 {{domxref("HTMLElement")}} 接口。</p>
+
+<h2 id="属性">属性</h2>
+
+<p><em>继承自父接口, {{domxref("HTMLElement")}}。</em></p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">名称</th>
+ <th scope="col">类型</th>
+ <th scope="col">描述</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>open</code></td>
+ <td>{{domxref("Boolean")}}</td>
+ <td>来自{{ htmlattrxref("open", "dialog") }} HTML 属性, 表示这个对话框可以进行互动.</td>
+ </tr>
+ <tr>
+ <td><code>returnValue</code></td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>用户获取对话框的值</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="方法">方法</h2>
+
+<p><em>继承自父接口 , {{domxref("HTMLElement")}}。</em></p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">名称和参数</th>
+ <th scope="col">类型</th>
+ <th scope="col">描述</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>close()</code> {{ HTMLVersionInline(5) }}</td>
+ <td><code>void</code></td>
+ <td>关闭对话框。 可选传入类型为{domxref("DOMString")}}的参数,用来更新对话框的returnValue。</td>
+ </tr>
+ <tr>
+ <td><code>show()</code> {{ HTMLVersionInline(5) }}</td>
+ <td><code>void</code></td>
+ <td>非模式化的显示这个对话框, 即:打开这个对话框之后依然可以和其他内容进行交互。 可选传入类型为 {{domxref("Element")}} 或者 {{domxref("MouseEvent")}} 的参数,用来定义对话框的显示位置。</td>
+ </tr>
+ <tr>
+ <td><code>showModal()</code> {{ HTMLVersionInline(5) }}</td>
+ <td><code>void</code></td>
+ <td>模式化的显示这个对话框, 并且将会至于所有其他对话框的顶层(屏蔽其他对话框的交互)。 可选传入类型为{{domxref("Element")}} 或者 {{domxref("MouseEvent")}} 的参数, 用来定义对话框的显示位置。</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Examples" name="Examples">Examples</h2>
+
+<h3 id="Example_1">Example 1</h3>
+
+<pre class="brush: html">&lt;!-- Anchor point example --&gt;
+&lt;dialog id="bronteDialog"&gt;
+ &lt;p&gt;That was part of a poem by Emily Brontë!&lt;/p&gt;
+&lt;/dialog&gt;
+
+&lt;blockquote&gt;
+ &lt;p&gt;"Then art thou glad to seek repose?&lt;br&gt;
+ Art glad to leave the sea,&lt;br&gt;
+ And &lt;strong id="anchor"&gt;anchor&lt;/strong&gt; all thy weary woes&lt;br&gt;
+ In calm Eternity?"&lt;/p&gt;
+&lt;/blockquote&gt;
+
+&lt;menu&gt;
+ &lt;button id="showDialogButton"&gt;Show dialog&lt;/button&gt;
+&lt;/menu&gt;
+
+&lt;script&gt;
+ (function() {
+ var showDialogButton = document.getElementById('showDialogButton');
+
+ // 'Show dialog' button opens dialog, anchored at third line of quote
+ showDialogButton.addEventListener('click', function() {
+ var bronteDialog = document.getElementById('bronteDialog');
+ var anchorPoint = document.getElementById('anchor');
+ bronteDialog.show(anchorPoint);
+ });
+
+ })();
+&lt;/script&gt;
+</pre>
+
+<h3 id="Example_2">Example 2</h3>
+
+<pre class="brush: html">&lt;!-- Simple pop-up dialog box, containing a form --&gt;
+&lt;dialog id="favDialog"&gt;
+ &lt;form method="dialog"&gt;
+ &lt;section&gt;
+ &lt;p&gt;&lt;label for="favAnimal"&gt;Favorite animal:&lt;/label&gt;
+ &lt;select id="favAnimal" name="favAnimal"&gt;
+ &lt;option&gt;&lt;/option&gt;
+ &lt;option&gt;Brine shrimp&lt;/option&gt;
+ &lt;option&gt;Red panda&lt;/option&gt;
+ &lt;option&gt;Spider monkey&lt;/option&gt;
+ &lt;/select&gt;&lt;/p&gt;
+ &lt;/section&gt;
+ &lt;menu&gt;
+ &lt;button id="cancel" type="reset"&gt;Cancel&lt;/button&gt;
+ &lt;button type="submit"&gt;Confirm&lt;/button&gt;
+ &lt;/menu&gt;
+ &lt;/form&gt;
+&lt;/dialog&gt;
+
+&lt;menu&gt;
+ &lt;button id="updateDetails"&gt;Update details&lt;/button&gt;
+&lt;/menu&gt;
+
+&lt;script&gt;
+ (function() {
+ var updateButton = document.getElementById('updateDetails');
+ var cancelButton = document.getElementById('cancel');
+
+ // Update button opens a modal dialog
+ updateButton.addEventListener('click', function() {
+ document.getElementById('favDialog').showModal();
+ });
+
+ // Form cancel button closes the dialog box
+ cancelButton.addEventListener('click', function() {
+ document.getElementById('favDialog').close();
+ });
+
+ })();
+&lt;/script&gt;
+</pre>
+
+<h2 id="Specifications" name="Specifications">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'forms.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>特性</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>37</td>
+ <td>{{CompatNo()}} {{bug(840640)}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>24</td>
+ <td>{{CompatNo()}}</td>
+ </tr>
+ <tr>
+ <td>Anchor points</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>特性</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ </tr>
+ <tr>
+ <td>Anchor points</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ <td>{{CompatNo()}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>The HTML element implementing this interface: {{ HTMLElement("dialog") }}.</li>
+</ul>
diff --git a/files/zh-cn/web/api/htmldialogelement/show/index.html b/files/zh-cn/web/api/htmldialogelement/show/index.html
new file mode 100644
index 0000000000..b5e43d3632
--- /dev/null
+++ b/files/zh-cn/web/api/htmldialogelement/show/index.html
@@ -0,0 +1,113 @@
+---
+title: HTMLDialogElement.show()
+slug: Web/API/HTMLDialogElement/show
+translation_of: Web/API/HTMLDialogElement/show
+---
+<p>{{ APIRef("HTML DOM") }} {{ SeeCompatTable() }}</p>
+
+<p>The <strong><code>show()</code></strong> method of the {{domxref("HTMLDialogElement")}} interface displays the dialog modelessly, i.e. still allowing interaction with content outside of the dialog.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox">dialogInstance.show();</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<p>None.</p>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>Void.</p>
+
+<h2 id="Examples" name="Examples">Examples</h2>
+
+<p>The following example shows a simple button that, when clicked, opens a {{htmlelement("dialog")}} containing a form via the <code>show()</code> method. From there you can click the <em>Cancel</em> button to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} method), or submit the form via the submit button.</p>
+
+<pre class="brush: html"> &lt;!-- Simple pop-up dialog box, containing a form --&gt;
+ &lt;dialog id="favDialog"&gt;
+ &lt;form method="dialog"&gt;
+ &lt;section&gt;
+ &lt;p&gt;&lt;label for="favAnimal"&gt;Favorite animal:&lt;/label&gt;
+ &lt;select id="favAnimal" name="favAnimal"&gt;
+ &lt;option&gt;&lt;/option&gt;
+ &lt;option&gt;Brine shrimp&lt;/option&gt;
+ &lt;option&gt;Red panda&lt;/option&gt;
+ &lt;option&gt;Spider monkey&lt;/option&gt;
+ &lt;/select&gt;&lt;/p&gt;
+ &lt;/section&gt;
+ &lt;menu&gt;
+ &lt;button id="cancel" type="reset"&gt;Cancel&lt;/button&gt;
+ &lt;button type="submit"&gt;Confirm&lt;/button&gt;
+ &lt;/menu&gt;
+ &lt;/form&gt;
+ &lt;/dialog&gt;
+
+ &lt;menu&gt;
+ &lt;button id="updateDetails"&gt;Update details&lt;/button&gt;
+ &lt;/menu&gt;
+
+ &lt;script&gt;
+ (function() {
+ var updateButton = document.getElementById('updateDetails');
+ var cancelButton = document.getElementById('cancel');
+ var dialog = document.getElementById('favDialog');
+ dialog.returnValue = 'favAnimal';
+
+ function openCheck(dialog) {
+ if(dialog.open) {
+ console.log('Dialog open');
+ } else {
+ console.log('Dialog closed');
+ }
+ }
+
+ // Update button opens a modal dialog
+ updateButton.addEventListener('click', function() {
+ dialog.showModal();
+ openCheck(dialog);
+ });
+
+ // Form cancel button closes the dialog box
+ cancelButton.addEventListener('click', function() {
+ dialog.close('animalNotChosen');
+ openCheck(dialog);
+ });
+
+ })();
+ &lt;/script&gt;</pre>
+
+<h2 id="Specifications" name="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'forms.html#dom-dialog-show', 'show()')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', 'interactive-elements.html#dom-htmldialogelement-show', 'show()')}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.HTMLDialogElement.show")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>The HTML element implementing this interface: {{ HTMLElement("dialog") }}.</li>
+</ul>