返回列表 發帖

請教MooTools

小弟初學MooTools
對其功能也並不熟悉
以下是一個簡單的MooTools+Html
但是alert()不會跳出來
可以請教是為甚麼嗎?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="mootools-core-1.3.2-full-compat.js">
</script>
<script type="text/javascript">
window.addEvent('domready', function(){
        $('listItem').setStyle('color', 'red');
        $('superList').setStyle('border', '1px solid #000000');
        alert($$('.lastItem').getFirst().get('text'));
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<ul id="superList">
        <li>List items</li>
    <li><a href="#">List item link</a></li>
    <li id="listItem">List item with an ID</li>
    <li class="lastItem">Last list item</li>
</ul>
</body>
</html>
謝謝!

回復 1# verymeanguy


    getFirst() 怪怪的, 改用 getLast() 就可以, 不知道為何...
To infinity and beyond!

TOP

謝謝!

我來看怎樣report bug

TOP

本帖最後由 ehomese 於 2011-9-2 21:38 編輯

添加已下代碼~就可以執行囉~
Array.implement({
    'getFirst': function(){
        return this[0];
    }
});
因為 function: $$ 的回傳值是Array(from Docs-1.2.5,console.log($type($$('.lastItem')));得結果也是),
而且mootools中的Array本身沒有getFirst這個function。

TOP

返回列表 回復 發帖