2019-04-21 11:50:48 +08:00

115 lines
7.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div> <div class="blockIndicator deprecated deprecatedHeader">
<p><strong><span class="icon-only-inline" title="This is an obsolete API and is no longer guaranteed to work."><i class="icon-trash"> </i></span> 已废弃</strong><br/>该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。</p>
</div></div>
<p>The <strong><code>fontsize()</code></strong> method creates a <a href="/zh-CN/docs/Web/HTML/Element/font" title="HTML Font 元素(&lt;font&gt;)定义了该内容的字体大小、顏色与表现。"><code>&lt;font&gt;</code></a> HTML element that causes a string to be displayed in the specified font size.</p>
<div class="note">
<p><strong>Usage note:</strong> The &lt;font&gt; element has been removed in <a href="/en-US/docs/Web/Guide/HTML/HTML5">HTML5</a> and shouldn't be used anymore. Instead web developers should use <a href="/en-US/docs/Web/CSS">CSS</a> properties.</p>
</div>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><code><var>str</var>.fontsize(<var>size</var>)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>size</code></dt>
<dd>An integer between 1 and 7, a string representing a signed integer between 1 and 7.</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p>A string containing a <a href="/zh-CN/docs/Web/HTML/Element/font" title="HTML Font 元素(&lt;font&gt;)定义了该内容的字体大小、顏色与表现。"><code>&lt;font&gt;</code></a> HTML element.</p>
<h2 id="描述">描述</h2>
<p>When you specify size as an integer, you set the font size of <code>str</code> to one of the 7 defined sizes. When you specify <code>size</code> as a string such as "-2", you adjust the font size of <code>str</code> relative to the size set in the <a href="/zh-CN/docs/Web/HTML/Element/basefont" title="HTML标签用来设置文档的默认字体大小。使用&lt;font&gt;可以相对于默认字体大小进行变化。"><code>&lt;basefont&gt;</code></a> tag.</p>
<h2 id="示例">示例</h2>
<h3 id="使用fontsize()方法"><code><font face="Open Sans, Arial, sans-serif">使用</font>fontsize()方法</code></h3>
<p>The following example uses string methods to change the size of a string:</p>
<pre><code class="language-javascript">var worldString = 'Hello, world';
console.log(worldString.small()); // &lt;small&gt;Hello, world&lt;/small&gt;
console.log(worldString.big()); // &lt;big&gt;Hello, world&lt;/big&gt;
console.log(worldString.fontsize(7)); // &lt;font size="7"&gt;Hello, world&lt;/fontsize&gt;
</code></pre>
<p>With the <a href="/zh-CN/docs/Web/API/HTMLElement/style" title="HTMLElement.style 属性返回一个 CSSStyleDeclaration 对象表示元素的 内联style 属性attribute但忽略任何样式表应用的属性。 通过 style 可以访问的 CSS 属性列表可以查看 CSS Properties Reference。"><code>element.style</code></a> object you can get the element's <code>style</code> attribute and manipulate it more generically, for example:</p>
<pre><code class="language-javascript">document.getElementById('yourElemId').style.fontSize = '0.7em';
</code></pre>
<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><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.fontsize" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">String.prototype.fontsize</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>Initial definition. Implemented in JavaScript 1.0. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.</td>
</tr>
<tr>
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-string.prototype.fontsize" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">String.prototype.fontsize</small></a></td>
<td><span class="spec-Draft">Draft</span></td>
<td>Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div></div>
<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</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td>1.0 (1.7 or earlier)</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for 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><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td>1.0 (1.0)</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="Reference/Global_Objects/String/big" title="big()方法的作用是创建一个使字符串显示大号字体的&lt;big&gt;标签。"><code>String.prototype.big()</code></a></li>
<li><a href="Reference/Global_Objects/String/small" title="small() 方法的作用是创建一个使字符串显示小号字体的 &lt;small&gt; 标签。"><code>String.prototype.small()</code></a></li>
</ul>
</article>