返回到:Prototype – 元素对象
此方法切换元素的 CSS 类名并返回元素。
语法
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 – 元素对象
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8989.html
支付宝
微信