aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlelement/title/index.html
blob: 340c56ef74a32eb91cebe3c106cf4784f5fed5fd (plain)
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
---
title: HTMLElement.title
slug: Web/API/HTMLElement/title
translation_of: Web/API/HTMLElement/title
---
<p>{{ APIRef() }}</p>

<p><strong><code>HTMLElement.title</code></strong> 属性表示元素的 title。当鼠标移到节点上时,会以“工具提示”(tool tip)的弹出形式显示该属性的属性值文本。</p>

<p>如果一个节点没有 <code>title</code> 属性(attribute),默认继承其父节点的相应属性,父节点可能是从父节点的父节点继承,依此类推。</p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="eval">var string = element.title;<em>
element.title</em> = <em>string</em>;
</pre>

<h2 id="Example" name="Example">例子</h2>

<pre><code>const link = document.createElement('a');
link.innerText = '葡萄';
link.href = 'https://en.wikipedia.org/wiki/Grape';
link.title = '维基百科上对葡萄的描述';</code></pre>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<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</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table>
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for 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>Basic support</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatVersionUnknown() }}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatVersionUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>