我有一个像这样的“ul”和“li”集合的下拉菜单,
<div style="float:left;">
<div class="group">
<div style="width:80px;">Dropdown<i class="fa fa-caret-down"></i></div>
<ul style="float:left;">
<li><a href="javascript:void(0);">Option1</a></li>
<li><a href="javascript:void(0);">Option2</a></li>
<li><a href="javascript:void(0);">Option3</a></li>
</ul>
</div>
</div>
我想将 onchange() 事件添加到 ul 标签。我可以说 onchange 我必须调用一个函数 SelectedItem(optionselected) 并将选定的“li”文本作为参数。任何人都请帮助我。谢谢。
最佳答案
The
change event
is sent to an element when its value changes. This event is limited to elements,<textarea>
boxes and<select>
elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.
参见 http://api.jquery.com/change/
所以 .change()
不适用于无序列表...
使用 click
事件
$('li').click(function(){
//your code
});
关于javascript - 如何给 ul 标签元素添加 onchange 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25520986/