diff options
author | Florian Merz <me@fiji-flo.de> | 2021-02-11 13:12:08 +0100 |
---|---|---|
committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 13:12:08 +0100 |
commit | 43a5cac2eff22c21071800e13bef12af9d3a37d0 (patch) | |
tree | f6e91f8aa958f15bd0b0aabf7b8dfc09063eceda /files/zh-tw/web/api/htmlelement | |
parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
download | translated-content-43a5cac2eff22c21071800e13bef12af9d3a37d0.tar.gz translated-content-43a5cac2eff22c21071800e13bef12af9d3a37d0.tar.bz2 translated-content-43a5cac2eff22c21071800e13bef12af9d3a37d0.zip |
unslug zh-tw: move
Diffstat (limited to 'files/zh-tw/web/api/htmlelement')
-rw-r--r-- | files/zh-tw/web/api/htmlelement/dataset/index.html | 167 | ||||
-rw-r--r-- | files/zh-tw/web/api/htmlelement/innertext/index.html | 86 | ||||
-rw-r--r-- | files/zh-tw/web/api/htmlelement/style/index.html | 79 |
3 files changed, 86 insertions, 246 deletions
diff --git a/files/zh-tw/web/api/htmlelement/dataset/index.html b/files/zh-tw/web/api/htmlelement/dataset/index.html deleted file mode 100644 index 690f8e1189..0000000000 --- a/files/zh-tw/web/api/htmlelement/dataset/index.html +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: HTMLElement.dataset -slug: Web/API/HTMLElement/dataset -translation_of: Web/API/HTMLOrForeignElement/dataset ---- -<p>{{ APIRef("HTML DOM") }}</p> - -<p><code><strong>HTMLElement.dataset</strong></code> 允許在讀取與寫入模式時使用HTML或DOM裡,所有設置在元件上的<a href="/en/HTML/Global_attributes#attr-data-*" title="https://developer.mozilla.org/en/HTML/Global_attributes#attr-data-*">自定義資料屬性</a>(<em>data-*</em>)。他是一個<a href="/en/DOM/DOMStringMap" title="en/DOM/DOMStringMap">DOMStringMap</a>,每個項目表示一個不同的資料屬性。須注意的是,資料集(dataset)可以被讀取,但不能直接被修改。所有修改必須經由其眾多"屬性"才行,也就是資料屬性。另外,雖然HTML <code><strong>data-</strong></code> 屬性與它相關的 DOM <code><strong>dataset.</strong></code> 名稱不同,但是他們總是有相似之處: </p> - -<ul> - <li>HTML裡的自定義資料屬性名稱開頭為<code>data-</code> 。後面則只接受字母、數字還有以下的符號: dash (<code>-</code>), 點 (<code>.</code>), 冒號 (<code>:</code>), 底線(<code>_</code>) -- 但不包含任何ASCII 大寫字母(A 到 Z)。</li> - <li>Javascript 裡的自定義資料屬性和HTML裡的一樣,只是命名規則採camelCase,且不含dash,點等上述所提的符號。</li> -</ul> - -<p>除了以下的資訊之外,你也可以在 <a href="/en-US/docs/Learn/HTML/Howto/Use_data_attributes">Using data attributes.</a>此篇文章找到使用HTML資料屬性的用法。</p> - -<h3 id="名稱變換">名稱變換</h3> - -<p> </p> - -<p>dash-style 到 camelCase: 將自訂義的資料屬性名稱變換至{{ domxref("DOMStringMap") }}各項目的key值,需根據以下規則:</p> - -<ul> - <li>移除前綴<code>data-</code>(包含dash)。</li> - <li>任何後面接ASCII小寫a到z的dash(<code>U+002D</code>)都要被移除,接在後面的字母被換成相對應的大寫字母。</li> - <li>其他字元(包含其他dashes)都保持不變。</li> -</ul> - -<p>camelCase 到 dash-style: 與上述相反,將key值轉為資料屬性名稱,需根據以下規則:</p> - -<ul> - <li>限制: dash 不能馬上接任何ASCII小寫字母a到z(在轉換之前)。</li> - <li>加上前綴字 <code>data-</code> 。</li> - <li>任何ASCII大寫字母A到Z變成dash加上其相對應的小寫字母。</li> - <li>其他字元都保持不變。</li> -</ul> - -<p>上面所提的限制是為了確保兩個轉換方法互為相反。</p> - -<p>舉例來說,資料屬性名稱 <code>data-abc-def</code> 之對應key值為<code>abcDef</code>。</p> - -<p> </p> - -<h3 id="存取數值">存取數值</h3> - -<ul> - <li>資料屬性可以藉由camelCase名稱(key)像dataset物件屬性的方式設定或讀取,如element.dataset.keyname。</li> - <li>資料屬性也可以經由物件屬性[]語法的方式設定或讀取,如 <em>element.</em>dataset[<em>keyname</em>]。</li> -</ul> - -<h2 id="語法">語法</h2> - -<ul> - <li><em>string</em> = <em>element</em>.<strong>dataset</strong>.<em>camelCasedName</em>;</li> - <li><em>element.</em><strong>dataset</strong>.<em>camelCasedName</em> = <em>string</em>;</li> - <br> - <li><em>string</em> = <em>element</em>.<strong>dataset</strong>[<em>camelCasedName</em>];</li> - <li><em>element</em>.<strong>dataset</strong>[<em>camelCasedName</em>] = <em>string</em>;</li> - <br> - <li><em>自定的data屬性也可以直接從HTML設定,但是屬性名稱必須使用上述中的data- 語法。 </em></li> -</ul> - -<h2 id="範例">範例</h2> - -<pre class="brush: js"><div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe</div> - -let el = document.querySelector('#user'); - -// el.id == 'user' -// el.dataset.id === '1234567890' -// el.dataset.user === 'johndoe' -// el.dataset.dateOfBirth === '' - -el.dataset.dateOfBirth = '1960-10-03'; // 設定 DOB. - -// 'someDataAttr' in el.dataset === false -el.dataset.someDataAttr = 'mydata'; -// 'someDataAttr' in el.dataset === true -</pre> - -<h2 id="規範">規範</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">規範</th> - <th scope="col">狀態</th> - <th scope="col">備註</th> - </tr> - <tr> - <td>{{SpecName('HTML WHATWG', "dom.html#dom-dataset", "HTMLElement.dataset")}}</td> - <td>{{Spec2('HTML WHATWG')}}</td> - <td>No change from latest snapshot, {{SpecName('HTML5.1')}}</td> - </tr> - <tr> - <td>{{SpecName('HTML5.1', "dom.html#dom-dataset", "HTMLElement.dataset")}}</td> - <td>{{Spec2('HTML5.1')}}</td> - <td>Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}</td> - </tr> - <tr> - <td>{{SpecName('HTML5 W3C', "dom.html#dom-dataset", "HTMLElement.dataset")}}</td> - <td>{{Spec2('HTML5 W3C')}}</td> - <td>Snapshot of {{SpecName('HTML WHATWG')}}, initial definition.</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>Edge</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>基本支援</td> - <td>8</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{ CompatGeckoDesktop("6.0") }}</td> - <td>11</td> - <td>11.10</td> - <td>6</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>功能</th> - <th>Android</th> - <th>Edge</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>基本支援</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile(6)}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="參見">參見</h2> - -<ul> - <li>The HTML <a href="/en-US/docs/Web/HTML/Global_attributes/data-*"><strong>data-*</strong></a> class of global attributes.</li> - <li><a href="/en-US/docs/Learn/HTML/Howto/Use_data_attributes">Using data attributes</a></li> -</ul> diff --git a/files/zh-tw/web/api/htmlelement/innertext/index.html b/files/zh-tw/web/api/htmlelement/innertext/index.html new file mode 100644 index 0000000000..4c8a4272fc --- /dev/null +++ b/files/zh-tw/web/api/htmlelement/innertext/index.html @@ -0,0 +1,86 @@ +--- +title: Node.innerText +slug: Web/API/Node/innerText +translation_of: Web/API/HTMLElement/innerText +--- +<div>{{APIRef("DOM")}}</div> + +<h2 id="概述">概述</h2> + +<p><code><strong>Node.innerText</strong></code> 是一個代表節點及其後代之「已渲染」(rendered)文字內容的屬性。如同一個存取器,<code>Node.innerText</code> 近似於使用者利用游標選取成高亮後複製至剪貼簿之元素的內容。此功能最初由 Internet Explorer 提供,並在被所有主要瀏覽器採納之後,於 2016 年正式成為 HTML 標準。</p> + +<p>{{domxref("Node.textContent")}} 屬性是一個相似的選擇,但兩者之間仍有非常不同的差異。</p> + +<h2 id="規範">規範</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', 'dom.html#the-innertext-idl-attribute', 'innerText')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Introduced, based on the <a href="https://github.com/rocallahan/innerText-spec">draft of the innerText specification</a>. See <a href="https://github.com/whatwg/html/issues/465">whatwg/html#465</a> and <a href="https://github.com/whatwg/compat/issues/5">whatwg/compat#5</a> for history.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_Compatibility" name="Browser_Compatibility">瀏覽器相容性</h2> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>4</td> + <td>{{ CompatGeckoDesktop(45) }}</td> + <td>6</td> + <td>9.6 (probably earlier)</td> + <td>3</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</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>2.3 (probably earlier)</td> + <td>{{ CompatGeckoMobile(45) }}</td> + <td>10 (probably earlier)</td> + <td>12</td> + <td>4.1 (probably earlier)</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="參見">參見</h2> + +<ul> + <li>{{domxref("HTMLElement.outerText")}}</li> + <li>{{domxref("Element.innerHTML")}}</li> +</ul> diff --git a/files/zh-tw/web/api/htmlelement/style/index.html b/files/zh-tw/web/api/htmlelement/style/index.html deleted file mode 100644 index e9e6d1171a..0000000000 --- a/files/zh-tw/web/api/htmlelement/style/index.html +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: HTMLElement.style -slug: Web/API/HTMLElement/style -translation_of: Web/API/ElementCSSInlineStyle/style ---- -<div>{{ APIRef("HTML DOM") }}</div> - -<p>The <code><strong>HTMLElement.style</strong></code> property is used to get as well as set the <strong>inline </strong>style of an element. While getting, it returns a <a href="/en-US/docs/DOM/CSSStyleDeclaration" title="DOM/CSSStyleDeclaration"><code>CSSStyleDeclaration</code></a> object that contains a list of all styles properties for that element with values assigned for the attributes that are defined in the element's <strong>inline</strong> <a href="/en-US/docs/Web/HTML/Global_attributes#style"><code>style</code> attribute</a>. See the <a href="/en-US/docs/Web/CSS/CSS_Properties_Reference" title="/en-US/docs/Web/CSS/CSS_Properties_Reference">CSS Properties Reference</a> for a list of the CSS properties accessible via <code>style</code>.The <code>style</code> property has the same (and highest) priority in the CSS cascade as an inline style declaration set via the <code>style</code> attribute.</p> - -<h3 id="設定_styles">設定 <code>styles</code></h3> - -<p>Styles can be set by assigning a string directly to the <code>style</code> property (as in<code> elt.style = "color: blue;") </code>or by assigning values to the properties of <code>style</code><code>. </code>For adding specific styles to an element without altering other style values, it is preferred to use the individual properties of <code>style</code> (as in<code> elt.style.color = '...' </code>) as using<code> elt.style.cssText = '...' or elt.setAttribute('style', '...')</code> sets the complete inline style for the element by overriding the existing inline styles. Note that the property names are in camel-case and not kebab-case while setting the style using <code>elt.style.<property> (</code>i.e.<code> elt.style.fontSize, </code>not<code> elt.style.font-size)</code></p> - -<h2 id="範例">範例</h2> - -<pre class="brush:js"><code>// Set multiple styles in a single statement -elt.style.cssText = "color: blue; border: 1px solid black"; -// OR -elt.setAttribute("style", "color:red; border: 1px solid blue;");</code> - - -elt.style.color = "blue"; // Set specific style while leaving other inline style values untouched -</pre> - -<h3 id="取得樣式資訊">取得樣式資訊</h3> - -<p>The <code>style</code> property is not useful for completely learning about the styles applied on the element, since it represents only the CSS declarations set in the element's inline <code>style</code> attribute, not those that come from style rules elsewhere, such as style rules in the {{HTMLElement("head")}} section, or external style sheets. To get the values of all CSS properties for an element you should use {{domxref("window.getComputedStyle()")}} instead.</p> - -<p>The following code snippet demonstrates the difference between the values obtained using the element's <code>style </code>property and that obtained using the <code>computedStyle()</code> method:</p> - -<pre class="brush: html"><!DOCTYPE HTML> -<html> - <body style="font-weight:bold;"> - - <div style="color:red" id="myElement">..</div> - - </body> -</html> -</pre> - -<pre class="brush:js">var element = document.getElementById("myElement"); -var out = ""; -var elementStyle = element.style; -var computedStyle = window.getComputedStyle(element, null); - -for (prop in elementStyle) { - if (elementStyle.hasOwnProperty(prop)) { - out += " " + prop + " = '" + elementStyle[prop] + "' > '" + computedStyle[prop] + "'\n"; - } -} -console.log(out) -</pre> - -<p>The output would be something like:</p> - -<pre>... -fontWeight = '' > 'bold' -color = 'red' > 'rgb(255, 0, 0)' -...</pre> - -<p>Note the presence of the value "bold" for font-weight in the computed style and the absence of it in the element's style property</p> - -<h2 id="Specification" name="Specification">規範</h2> - -<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle">DOM Level 2 Style: ElementCSSInlineStyle.style</a></p> - -<h2 id="瀏覽器相容性">瀏覽器相容性</h2> - -<div class="note"> -<p><strong>Note:</strong> Starting in {{Gecko("2.0")}}, you can set SVG properties' values using the same shorthand syntax. For example:</p> - -<pre><code>element.style.fill = 'lime';</code></pre> -</div> - -<h2 id="參見">參見</h2> - -<ul> - <li><a href="/en-US/docs/DOM/Using_dynamic_styling_information" title="DOM/Using dynamic styling information">Using dynamic styling information</a></li> -</ul> |