简体   繁体   English

如何使整个菜单栏项目区域可单击

[英]how to make whole menu bar item area clickable

i 'm working with menu bar control. 我正在使用菜单栏控件。 here is my css and design code: 这是我的CSS和设计代码:

css : css:

.Menu 
{ 
    background:transparent url(../images/blueslate_background.gif) repeat-x;
    text-align:center;
    font-family : "lucida grande", tahoma, verdana, arial, sans-serif;
    font-size:12px;
    font-weight:bold;
    border: None 0px #fff !important;
}

.menuhover
{
     color:#fff;
     background:transparent url(../images/blueslate_backgroundOVER.gif) repeat-x left center;
     cursor:pointer;
}

design : 设计

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuControl.ascx.cs" Inherits="MenuControl" %>
<link rel="stylesheet" href="css/Menu3.css" type="text/css" />
<div id="header" align="center" >
<table width="100%" cellpadding ="0" cellspacing ="0" align="center">
<tr>
<td align="center">
   <asp:Menu ID="Menu1" runat="server" Orientation ="Horizontal"  CssClass="Menu"
        ForeColor ="Black" Width="100%" ScrollDownText="">
     <StaticMenuItemStyle Height ="40px"/>
    <DynamicMenuItemStyle CssClass ="Menu" Height="30px" HorizontalPadding="10px"/>
    <dynamichoverstyle  CssClass ="menuhover"/>
    <StaticHoverStyle CssClass ="menuhover"/>
    </asp:Menu>
</td>
</tr>
</table>
</div>

i just want to make whole menu bar list item area clickable is it possible with jquery or javascript. 我只想使整个菜单栏列表项区域可单击,是否可以使用jquery或javascript。

------------------------------------Updated----------------------------------------------------- - - - - - - - - - - - - - - - - - - 更新 - - - - - - - ----------------------------------------

here is some example to make whole div clickable with jquery: 这是使整个div可通过jquery点击的示例:

<script type="text/javascript" language="javascript">
$(document).ready(function(){                 
     $(".thumb").click(function(){
     window.location=$(this).find("a").attr("href");return false;
     });
});
</script>

------------------------------------Updated----------------------------------------------------- - - - - - - - - - - - - - - - - - - 更新 - - - - - - - ----------------------------------------

solution : 解决方案:

    <script type="text/javascript" language="javascript">
$(document).ready(function() {                 
     $(".Menu").click(function(e) {
         window.location = $(e.target).find("a").attr("href");
         return false;
     });
});
</script>

Error occurs when i clicks original Menu Text Error: 当我单击原始菜单文本错误时发生错误:

Server Error in '/EasyWeb' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /EasyWeb/undefined

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

Maybe you want to check if "header" is clicked and then check what element has been clicked.. 也许您想检查是否单击了“标题”,然后检查是否单击了哪个元素。

In this case you have to check, with JQuery for instance: 在这种情况下,您必须使用JQuery进行检查:

$('#header').on('click', function(e) {
    var what = $(e.target).html();
    $('#clicked').html("You have selected: " + what);
});

Take a look on this DEMO . 看看这个演示
Or this one , more nice. 还是这个 ,更好。

Edit 编辑

To check also href in a element, take a look here . 要同时检查href中的元素,请在此处查看

Edit2 编辑2

$(document).ready(function() {                 
     $(".Menu").click(function(e) {
         window.location = $(e.target).find("a").attr("href");
         return false;
     });
});

You can provide a click handler for the elements with the .Menu class. 您可以使用.Menu类为元素提供点击处理程序。

$(document).on("click", ".Menu", function(){
  alert("Menu clicked");
}) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM