- 原型教程
- 原型 - 主页
- 原型 - 简要概述
- 原型 - 实用功能
- 原型 - 实用方法
- 原型 - 元素对象
- 原型 - 数字处理
- 原型 - 字符串处理
- 原型 - 数组处理
- 原型 - 哈希处理
- 原型 - 基本对象
- 原型 - 模板化
- 原型 - 枚举
- 原型 - 事件处理
- 原型 - 表单管理
- 原型 - 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
广告