返回到:Prototype – 元素对象
此方法切换元素的 CSS 类名并返回元素。
语法
element.toggleClassName( className );
返回值
返回一个 HTML 元素。
例子
HTML
x
33
33
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
if( !$('mutsu').hasClassName('fruit') ) {
9
// This will return false
10
alert( "Class name is not set" );
11
}
12
$('mutsu').toggleClassName('fruit');
13
14
// This will toggle the class presence
15
if( $('mutsu').hasClassName('fruit') ) {
16
// This returns true
17
alert( "Now Class name is set" );
18
}
19
}
20
</script>
21
</head>
22
23
<body>
24
<p>Click the button to see the result.</p>
25
26
<div id = "mutsu" class = "apple">
27
<p>This is test division.</p>
28
</div>
29
<br />
30
31
<input type = "button" value = "showResult" onclick = "showResult();"/>
32
</body>
33
</html>
返回到:Prototype – 元素对象
阅读剩余 47%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8989.html