获取UL中锚标记的属性值

时间:2013-03-04 12:54:15

标签: mootools

<div class="content">
    <ul class="clean menu" id="topics">
        <li class="drop png">
            <div>
                <span href="#" id="phone" style="BACKGROUND-POSITION: 13px -79px">Phone</span>
            </div>
            <ul class="clean menu sub">
               <li>
                   <a cat="tech" class="sec_phone_0" href="javascript:void(0);" name="&amp;lid=choose_category_phone_digital" rel="1">FiOS Digital Voice</a>
               </li>
               <li class="last">
                   <a cat="tech" class="sec_phone_1" href="javascript:void(0);" name="&amp;lid=choose_category_phone_dialup" rel="1">Home Phone(Copper)</a>
               </li>
               <li class="last">
                   <a cat="tech" class="sec_phone_2" href="javascript:void(0);" name="&amp;lid=choose_category_phone_fiosVoice" rel="1">FiOS Voice</a>
               </li>
               <li class="last" style="margin-bottom:7px;">
                   <a cat="tech" class="sec_phone_2" href="javascript:void();" name="&amp;lid=choose_category_phone_wireless" rel="1">Verizon Wireless</a>
               </li>
           </ul>
       </li>
    </ul>
</div>

现在我需要选择Fios Voice的“cat”值。我怎么能在Mootools v1.3.2中做到这一点? 需要在cookie中设置值。

1 个答案:

答案 0 :(得分:1)

此脚本获取点击事件链接的属性。

window.addEvent('domready',function(){
    $$('ul.sub')[0].getElements('a').each(function(el,ind){
        el.addEvent('click',function(){
            var cat = el.getProperty('cat');
            alert(cat)
        })
    })
})

对于<a cat="tech1" class="sec_phone_0 active" href="javascript:void(0);" name="&amp;lid=choose_category_phone_digital" rel="1">FiOS Digital Voice</a>class="active"

的情况
window.addEvent('domready',function(){
    if($$('ul.sub')[0].getElements('a.active')[0]){
        var cat = $$('ul.sub')[0].getElement('a.active').getProperty('cat');
        alert(cat);
    }
})