NavigateUrl 未在 MenuItem 中调用 javascript
我似乎不明白为什么菜单项没有调用我的 asp.net 菜单中的 javascript 功能。当我单击菜单项时,菜单将关闭并且不会执行任何进一步操作。我的部分代码如下所示:
<asp:Panel runat="server" ID="MenuPanel" CssClass="MenuPanel" style="display: none">
<asp:Menu ID="MyMenu" runat="server" CssClass="Menu" ForeColor="Black"
BorderStyle="Double" BorderColor="Gray" BorderWidth="1px">
<StaticMenuItemStyle BackColor="#DBDDE0" CssClass="MenuItem" />
<StaticHoverStyle BackColor="#CCCDCE" />
<Items>
<asp:MenuItem Text='Item 1' Value="0" Selectable="true" NavigateUrl="javascript:alert('hello world 1')" ImageUrl="~/image1.gif"/>
<asp:MenuItem Text='Item 2' Value="1" Selectable="true" NavigateUrl="javascript:alert('hello world 2')" ImageUrl="~/image2.gif" />
</Items>
</asp:Menu>
</asp:Panel>
更新 1
当进一步测试发现,当我注释掉被单击元素(调出菜单的元素)的 onBlur 事件时,我正要转储浏览器输出,JavaScript 按预期工作。
当焦点从元素移开时,onBlur 事件中的代码会隐藏弹出菜单。第二次单击菜单项本身触发了 onBlur 事件,该事件隐藏了菜单。看来由于菜单是隐藏的,与其关联的 JavaScript 不会被调用。
I can't seem to figure why the menu item is not invoking the javascript functionality in my asp.net menu. When I click on the menu item, the menu closes and does not do anything further. A portion of my code is shown below:
<asp:Panel runat="server" ID="MenuPanel" CssClass="MenuPanel" style="display: none">
<asp:Menu ID="MyMenu" runat="server" CssClass="Menu" ForeColor="Black"
BorderStyle="Double" BorderColor="Gray" BorderWidth="1px">
<StaticMenuItemStyle BackColor="#DBDDE0" CssClass="MenuItem" />
<StaticHoverStyle BackColor="#CCCDCE" />
<Items>
<asp:MenuItem Text='Item 1' Value="0" Selectable="true" NavigateUrl="javascript:alert('hello world 1')" ImageUrl="~/image1.gif"/>
<asp:MenuItem Text='Item 2' Value="1" Selectable="true" NavigateUrl="javascript:alert('hello world 2')" ImageUrl="~/image2.gif" />
</Items>
</asp:Menu>
</asp:Panel>
Update 1
I was about to dump out the browser output when further testing revealed that when I commented out the onBlur event of the element being clicked (the element that brings up the menu), the javascript worked as expected.
The code in the onBlur event hides the pop-up menu when focus is moved away from the element. The second click on the menu item itself triggered the onBlur event which hides the menu. It seems that since the menu is hidden, the javascript associated with it does not get invoked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器中的输出是什么样的?
使用viewsource或firebug或IE调试器看一下。
使用 onclick 可以更好地处理这个问题:
What does the output look like in the browser?
Use viewsource or firebug or IE debugger to take a look.
This would be better handled by using onclick:
我认为你应该尝试 JQuery
I think you should try JQuery