- Prototype 教程
- Prototype - 主页
- Prototype - 简要概述
- Prototype - 有用功能
- Prototype - 实用程序方法
- Prototype - 元素对象
- Prototype - 数字处理
- Prototype - 字符串处理
- Prototype - 数组处理
- Prototype - 哈希处理
- Prototype - 基本对象
- Prototype - 模板化
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表达范围
- Prototype - 周期性执行
- Prototype 有用资源
- Prototype - 快速指南
- Prototype - 有用资源
- Prototype - 讨论
Prototype - toggleClassName() 方法
此方法切换元素的 CSS className 并返回元素。
语法
element.toggleClassName( className );
返回值
返回一个 HTML 元素。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
if( !$('mutsu').hasClassName('fruit') ) {
// This will return false
alert( "Class name is not set" );
}
$('mutsu').toggleClassName('fruit');
// This will toggle the class presence
if( $('mutsu').hasClassName('fruit') ) {
// This returns true
alert( "Now Class name is set" );
}
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<div id = "mutsu" class = "apple">
<p>This is test division.</p>
</div>
<br />
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>
输出
prototype_element_object.htm
广告