我正在尝试在我的 jquery 菜单 ui 中获取所选 ui.item 的名称属性。我需要添加了“选定”类的项目的名称属性,但 attr('name') 返回未定义。单击提交按钮时,我需要获取该名称属性。
<script>
$(function () {
var selection = ' ';
$(".menu").menu({
select: function (event, ui) {
$('.selected', this).removeClass('selected');
selection = ui.item.addClass('selected').attr('name');
} // closes select function
}); // closes menu
$("button").button();
$("button").click(function () {
alert(selection)
}); //closes click()
});
</script>
<ul class="menu" id="menu">
<li>
<a href="#" name="academic_artStudies">
<img src="" alt="" />
<h2>Academic: Art Studies</h2>
</a>
</li>
<li>
<a href="#" name="academic_Literature">
<img src="" alt="" />
<h2>Academic: Literature</h2>
</a>
</li>
<li>
<a href="#" name="academic_socialSciences">
<img src="" alt="" />
<h2>Academic: Social Sciences</h2>
</a>
</li>
<li>
<a href="#" name="academic_physicalNaturalSci">
<img src="" alt="" />
<h2>Academic: Physical/Natural Sciences</h2>
</a>
</li>
</ul>