aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/copy_event/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/element/copy_event/index.html')
-rw-r--r--files/zh-cn/web/api/element/copy_event/index.html164
1 files changed, 164 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/copy_event/index.html b/files/zh-cn/web/api/element/copy_event/index.html
new file mode 100644
index 0000000000..ac249f5055
--- /dev/null
+++ b/files/zh-cn/web/api/element/copy_event/index.html
@@ -0,0 +1,164 @@
+---
+title: copy
+slug: Web/Events/copy
+tags:
+ - Clipboard API
+ - Event
+ - Reference
+translation_of: Web/API/Element/copy_event
+---
+<p>当用户通过浏览器UI(例如,使用 <kbd>Ctrl</kbd>/<kbd>⌘</kbd>+<kbd>C</kbd>  键盘快捷方式或从菜单中选择“复制”)启动复制操作并响应允许的{{domxref("Document.execCommand","document.execCommand('copy')")}}调用时触发<code>copy</code>事件。</p>
+
+<h2 id="基本信息">基本信息</h2>
+
+<dl>
+ <dt style="float: left; text-align: right; width: 120px;">Specification</dt>
+ <dd style="margin: 0 0 0 120px;"><a class="external" href="https://www.w3.org/TR/clipboard-apis/#the-copy-action">Clipboard</a></dd>
+ <dt style="float: left; text-align: right; width: 120px;">Interface</dt>
+ <dd style="margin: 0 0 0 120px;">{{domxref("ClipboardEvent")}}</dd>
+ <dt style="float: left; text-align: right; width: 120px;">Bubbles</dt>
+ <dd style="margin: 0 0 0 120px;">Yes</dd>
+ <dt style="float: left; text-align: right; width: 120px;">Cancelable</dt>
+ <dd style="margin: 0 0 0 120px;">Yes</dd>
+ <dt style="float: left; text-align: right; width: 120px;">Target</dt>
+ <dd style="margin: 0 0 0 120px;">{{domxref("Element")}}:获得焦点的元素(如{{domxref("HTMLElement.contentEditable","contentEditable")}}内容能编辑或者可以选中的元素),或{{HTMLElement("body")}}。</dd>
+ <dt style="float: left; text-align: right; width: 120px;">Default Action</dt>
+ <dd style="margin: 0 0 0 120px;">见下文。</dd>
+</dl>
+
+<p>调用{{domxref("DataTransfer.setData","setData(format, data)")}}可以修改{{domxref("ClipboardEvent.clipboardData")}}事件的默认行为:</p>
+
+<pre class="brush: js">document.addEventListener('copy', function(e){
+ e.clipboardData.setData('text/plain', 'Hello, world!');
+ e.clipboardData.setData('text/html', '&lt;b&gt;Hello, world!&lt;/b&gt;');
+ e.preventDefault(); // We want our data, not data from any selection, to be written to the clipboard
+});</pre>
+
+<p>不能使用{{domxref("DataTransfer.getData", "clipboardData.getData()")}}在事件处理函数中获取剪切板数据。</p>
+
+<p>事件的默认行为与事件的来源和事件处理函数相关:</p>
+
+<ul>
+ <li><a href="/en-US/docs/Web/Guide/Events/Creating_and_triggering_events">synthetic</a> copy事件没有默认行为,除非:</li>
+ <li>如果默认事件没有取消,就复制到选区(如果有选中内容)到剪切板;</li>
+ <li>如果取消了默认事件,但是调用了<code>setData()</code>方法:就复制<code>clipboardData</code>的内容到到剪切板;</li>
+ <li>如果取消了默认行为,而且没有调用<code>setData()</code>方法,就没有任何行为。</li>
+</ul>
+
+<h2 id="属性">属性</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Property</th>
+ <th scope="col">Type</th>
+ <th scope="col">Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>target</code> {{readonlyInline}}</td>
+ <td>{{domxref("EventTarget")}}</td>
+ <td>The event target (the topmost target in the DOM tree).</td>
+ </tr>
+ <tr>
+ <td><code>type</code> {{readonlyInline}}</td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>The type of event.</td>
+ </tr>
+ <tr>
+ <td><code>bubbles</code> {{readonlyInline}}</td>
+ <td>{{jsxref("Boolean")}}</td>
+ <td>Whether the event normally bubbles or not.</td>
+ </tr>
+ <tr>
+ <td><code>cancelable</code> {{readonlyInline}}</td>
+ <td>{{jsxref("Boolean")}}</td>
+ <td>Whether the event is cancellable or not.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ <tr>
+ <td><code>clipboardData</code></td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatGeckoDesktop(22) }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ <tr>
+ <td><code>clipboardData</code></td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatGeckoMobile(22) }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{domxref("HTMLElement.oncopy")}}</li>
+ <li>Related events
+ <ul>
+ <li>{{event("cut")}}</li>
+ <li>{{event("paste")}}</li>
+ </ul>
+ </li>
+</ul>