- 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
廣告