返回到:Prototype – 元素对象
此方法测试元素是否为空(即,仅包含空格)。
语法
element.empty;
返回值
如果发现元素为空,则返回 true,否则返回 false。
例子
HTML
x
25
25
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
if($('wallet').empty() ) {
9
alert( "Wallet is empty " );
10
}
11
if($('cart').empty() ) {
12
alert( "Cart is full" );
13
}
14
}
15
</script>
16
</head>
17
18
<body>
19
<p>Click the button to see the result.</p>
20
<div id = "wallet"> </div>
21
<div id = "cart">full!</div>
22
<br />
23
<input type = "button" value = "showResult" onclick = "showResult();"/>
24
</body>
25
</html>
在这个例子中:
$('wallet').empty(); // -> true $('cart').empty(); // -> false
返回到:Prototype – 元素对象
阅读剩余 43%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9120.html