- 原型教程
- 原型 - 主頁
- 原型 - 簡要概述
- 原型 - 實用功能
- 原型 - 實用方法
- 原型 - 元素物件
- 原型 - 數字處理
- 原型 - 字串處理
- 原型 - 陣列處理
- 原型 - 雜湊處理
- 原型 - 基本物件
- 原型 - 模板化
- 原型 - 列舉
- 原型 - 事件處理
- 原型 - 表單管理
- 原型 - JSON 支援
- 原型 - AJAX 支援
- 原型 - 表達範圍
- 原型 - 週期執行
- 原型有用的資源
- 原型 - 快速指南
- 原型 - 有用的資源
- 原型 - 討論
原型 - hasClassName() 方法
此方法檢查元素是否擁有給定的 CSS className。
語法
element.hasClassName( className );
返回值
如果元素擁有給定的類名則返回 true,否則返回 false。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
if( $('grandfather').hasClassName("test") ) {
alert("Grandfather has CSS test class.");
}
if( $('father').hasClassName("test") ) {
alert("Father has CSS test class.");
}
if( $('kid').hasClassName("test") ) {
alert("Kid has CSS test class.");
}
}
</script>
<style>
.test {
font-size: 12px;
margin-left: 1em;
}
</style>
</head>
<body>
<p>Click the button to see the result.</p>
<div id = "grandfather" class = "test">This is grand father
<div id = "father"> This is father.
<div id = "kid" class = "test">This is kid</div>
</div>
</div>
<br />
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_element_object.htm
廣告