【发布时间】:2017-11-01 12:14:06
【问题描述】:
这是我的 html 代码:
<div class="wrapper-demo">
<div id="dd" class="wrapper-dropdown-3" tabindex="1">
<span>The Dropdown</span>
<ul class="dropdown">
<li>@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })</li>
<li>@Html.ActionLink("Company Information", "Details", "Employer",routeValues: new {id = Model.ID },htmlAttributes: null)</li>
<li>@Html.ActionLink("Post Opening", "Create", "Opening")</li>
<li>@Html.ActionLink("View Opening", "Details", "Opening")</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
</div>
我的示例 jquery 代码来自:
function DropDown(el) {
this.dd = el;
this.placeholder = this.dd.children('span');
this.opts = this.dd.find('ul.dropdown > li');
this.val = '';
this.index = -1;
this.initEvents();
}
DropDown.prototype = {
initEvents : function() {
var obj = this;
//show dropdown items on click
obj.dd.on('click', function (event) {
$(this).toggleClass('active');
});
obj.opts.on('click', function () {
var opt = $(this);
obj.val = opt.text();
obj.index = opt.index();
obj.placeholder.text(obj.val);
});
},
getValue : function() {
return this.val;
},
getIndex : function() {
return this.index;
}
}
$(function() {
var dd = new DropDown( $('#dd') );
$(document).click(function() {
// all dropdowns
$('.wrapper-dropdown-3').removeClass('active');
});
});
问题:该代码的工作方式类似于静态 href 代码,它无处可去,但它有一个有效的锚链接可供导航。我怎样才能让它工作?
【问题讨论】:
标签: javascript jquery html model-view-controller