1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
---
title: String.prototype.fontsize()
slug: Web/JavaScript/Reference/Global_Objects/String/fontsize
translation_of: Web/JavaScript/Reference/Global_Objects/String/fontsize
---
<div>{{JSRef}} {{deprecated_header}}</div>
<p>The <strong><code>fontsize()</code></strong> method creates a {{HTMLElement("font")}} HTML element that causes a string to be displayed in the specified font size.</p>
<div class="note">
<p><strong>备注:</strong> The <font> 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 class="syntaxbox"><code><var>str</var>.fontsize(<var>size</var>)</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 {{HTMLElement("font")}} 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 {{HTMLElement("basefont")}} tag.</p>
<h2 id="示例">示例</h2>
<h3 id="使用fontsize()方法"><code>使用fontsize()方法</code></h3>
<p>The following example uses string methods to change the size of a string:</p>
<pre class="brush: js">var worldString = 'Hello, world';
console.log(worldString.small()); // <small>Hello, world</small>
console.log(worldString.big()); // <big>Hello, world</big>
console.log(worldString.fontsize(7)); // <font size="7">Hello, world</fontsize>
</pre>
<p>With the {{domxref("HTMLElement.style", "element.style")}} object you can get the element's <code>style</code> attribute and manipulate it more generically, for example:</p>
<pre class="brush: js">document.getElementById('yourElemId').style.fontSize = '0.7em';
</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>{{SpecName('ES6', '#sec-string.prototype.fontsize', 'String.prototype.fontsize')}}</td>
<td>{{Spec2('ES6')}}</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>{{SpecName('ESDraft', '#sec-string.prototype.fontsize', 'String.prototype.fontsize')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td>Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat}}
<h2 id="相关链接">相关链接</h2>
<ul>
<li>{{jsxref("String.prototype.big()")}}</li>
<li>{{jsxref("String.prototype.small()")}}</li>
</ul>
|