点击<a> to show <ul>, but click other to hide the <ul></ul></ul></a>

时间:2013-05-31 03:39:01

标签: javascript jquery html prototypejs show-hide

我想创建一个<UL>列表,例如<SELECT>行为,但onclick<A>标记。任何人都可以解决问题吗?

HTML:

<div class="btn-group">
    <a class="grey-btn btn btn-mini" onclick="<?php echo $this->getJsModel(); ?>.showHideAction(<?php echo $i; ?>);">Action</a>
    <a class="grey-btn btn btn-mini dropdown-toggle" onclick="<?php echo $this->getJsModel(); ?>.showHideAction(<?php echo $i; ?>)">
        <span class="caret"></span>
    </a>
    <ul id="dropdown_action_<?php echo $i; ?>" name="dropdown_action_<?php echo $i; ?>" class="dropdown-menu" style="display:none;">
        <li style="cursor:pointer;" onClick="<?php echo $this->getJsModel(); ?>.activeAddtocartSubmit(<?php echo $i; ?>, <?php echo $collection->getSize(); ?>, '<?php echo $_url; ?>', '<?php echo $this->getForm(); ?>');">Add to Cart</li>
    </ul>
</div>

使用Javascript:

showHideAction : function(i){
    $('dropdown_action_'+i).toggle();
},

1 个答案:

答案 0 :(得分:3)

更改

$('dropdown_action_'+i).toggle();

$('#dropdown_action_'+i).toggle(); // '#' is used to select element with specified id