返回到:Prototype – 元素对象
如果未指定属性,则此方法返回元素属性的值或 null。
语法
element.readAttribute(attribute);
返回值
返回元素属性的值,如果未指定属性,则返回 null。
例子
HTML
x
28
28
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var str = $('tag').readAttribute('href');
9
alert("Value of href : " + str );
10
11
var str = $('tag').readAttribute('title');
12
alert("Value of title : " + str );
13
14
var str = $('tag').readAttribute('somethingelse');
15
alert("Value ofsomething else : " + str );
16
}
17
</script>
18
</head>
19
20
<body>
21
<p>Click the button to see the result.</p>
22
<a id = "tag" href = "/tags/prototype" rel = "tag"
23
title = "view related bookmarks.">Prototype</a>
24
<br />
25
<br />
26
<input type = "button" value = "Show Result" onclick = "showResult();"/>
27
</body>
28
</html>
返回到:Prototype – 元素对象
阅读剩余 42%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9049.html