我有一个菜单,每个项目都可以切换它自己的子菜单,这里是示例代码。如您所见,子菜单项是链接到 google.co.nz 的标签
<ul id="menuHolder">
<li data-bind="click: showMenu.bind($data, 1)">
Main menu item
<ul class="submenu" data-bind="visible: selected() == '1'">
<li>
<a class="sub-item" href="http://google.co.nz">
Submenu item
</a>
</li>
</ul>
</li>
</ul>
<script type="text/javascript">
var menuModel = function () {
var self = this;
self.selected = ko.observable(0);
self.showMenu = function (data) {
var s = self.selected();
if (s > 0 && data == s)
self.selected(0);
else
self.selected(data);
};
}
ko.applyBindings(new menuModel(), document.getElementById("menuHolder"));
</script>
一切都有效,只有 a 标签不再有效,这里有什么问题?