我可能误解了你,但这至少会给你一个想法。
资源:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
html:
<label id="LabelMenu" text="" runat="server" />
<span id="menuSelection">My Span List</span>
jQuery:
$(document).ready(function(){
// Flag to prevent multiple insertion
var flag = false;
$("#menuSelection").click(function() {
// Prevent inserting more than 1 menu
if (flag == false) {
// Your menu
$('<ul id="mylist"> <li><a href="#">First Level 1</a> <ul> <li><a href="#">FL1 Second Level 1</a></li> <li><a href="#">FL1 Second Level 2</a></li> </ul> </li> <li><a href="#">First Level 2</a> <ul> <li><a href="#">FL2 Second Level 1</a> <ul> <li><a href="#">FL2 SL1 Third Level 1</a></li> </ul> </li> <li><a href="#">FL2 Second Level 2</a> <ul> <li><a href="#">FL2 SL2 Third Level 1</a></li> </ul> </li> <li><a href="#">FL2 Second Level 3</a></li> </ul> </li> <li><a href="#">First Level 3</a> <ul> <li><a href="#">FL3 Second Level 1</a> <ul> <li><a href="#">FL3 SL1 Third Level 1</a></li> <li><a href="#">FL3 SL1 Third Level 2</a></li> </ul> </li> <li><a href="#">FL3 Second Level 2</a></li> <li><a href="#">FL3 Second Level 3</a> <ul> <li><a href="#">FL3 SL3 Third Level 1</a></li> </ul> </li> </ul> </li> <li><a href="#">First Level 4</a> </li> </ul>'
).insertAfter($(this)).menu().focus().focusout(function() {
// When out of menu remove this instance
$(this).empty().remove();
// Flag false again
flag = false;
});
// Find which menu item is clicked
$('#mylist a').click(function() {
var route=$(this).parent().text();
if($(this).next().length==0){
alert('no more levels');
alert(route);
$('#LabelMenu').text(route);
}else{
alert(route);
$('#LabelMenu').text($(this).text());
}
});
}
// Change flag on click
flag = true;
});
});
小提琴:http: //jsfiddle.net/BerkerYuceer/gp6H5/