blob: d023340f7833700aaac9f53f0a8a22f2e74497d2 (
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
|
---
title: href
slug: Web/API/StyleSheet/href
translation_of: Web/API/StyleSheet/href
---
<div>{{APIRef("CSSOM")}}</div>
<h3 id="Summary" name="Summary">概述</h3>
<p>返回当前样式表文件的URI地址.</p>
<h3 id="Syntax" name="Syntax">语法</h3>
<pre class="eval"><em>uri</em> = stylesheet.href
</pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<ul>
<li><code>uri</code> 为一个字符串,包含了样式表文件的URI地址.</li>
</ul>
<h3 id="Example" name="Example">例子</h3>
<pre> // 在本机环境下
<html>
<head>
<link rel="StyleSheet" href="example.css" type="text/css" />
<script>
function sref() {
alert(document.styleSheets[0].href);
}
</script>
</head>
<body>
<div class="thunder">Thunder</div>
<button onclick="sref()">ss</button>
</body>
</html>
// 弹出 "file:////C:/Windows/Desktop/example.css
</pre>
<h3 id="Notes" name="Notes">备注</h3>
<p>如果该样式表是一个外链样式表文件,则它的href属性值为样式表文件的URI. 但如果该样式表是一个内联样式表,则它的href属性值为<code>null</code>.</p>
<p>该属性在Firefox, Opera, Google Chrome, Safari中为只读属性,在Internet Explorer中可读可写.</p>
<h3 id="Specification" name="Specification">规范</h3>
<p><a class="external" href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html#StyleSheets-StyleSheet-href">stylesheet.href </a></p>
<p>{{ languages( {"en": "en/DOM/StyleSheet/href" } ) }}</p>
|