菜单导航不工作与jquery datepicker

问题描述:

我有数据库生成菜单与我的MVC4的Web应用程序中的子菜单项,这是工作正常,直到我没有实现JQuery的日期选择器。 只要我包含datetimepicker.js和jqueryui包,我的菜单停止开销。我曾试图改变脚本和风格的顺序,但没有成功。我对css相当陌生,所以我无法弄清楚这里出了什么问题。菜单导航不工作与jquery datepicker

这里是我的_Layout.cshtml:

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <title>@ViewBag.Title</title> 
     <link href="~/Images/Company-logo/logo.ico" rel="shortcut icon" type="image/x-icon" /> 
     <meta name="viewport" content="width=device-width" /> 

     @Scripts.Render("~/bundles/jquery") 
     @Scripts.Render("~/bundles/modernizr") 
     @Scripts.Render("~/bundles/jqueryui") 
     @Styles.Render("~/Content/themes/base/css","~/Content/themes/base", "~/Content/css") 
     <script src="~/Scripts/DatePickerReady.js"></script> 
     <link href="~/Content/indexView.css" rel="stylesheet" /> 
    </head> 
    <body> 
     <header> 
      <div> 
       <img src="~/Images/Company-logo/header_bar.png" style="width:100%"/> 
      </div> 

      <div class="content-wrapper"> 
       <div class="float-right"> 
        @Html.Partial("Menu") 
       </div> 
      </div> 
     </header> 
     <div id="body"> 
      @RenderSection("featured", required: false) 
      <section class="content-wrapper main-content clear-fix"> 
       @RenderBody() 
      </section> 
     </div> 
     <footer> 

     </footer> 

     <script src="@Url.Content("~/Scripts/dbGeneratedMenu.js")" type="text/javascript"></script> 
     <link href="@Url.Content("~/Content/dbGeneratedMenu.css")" rel="stylesheet" type="text/css" /> 
     @RenderSection("scripts", required: false) 
    </body> 

    <script type="text/javascript"> 
     $m = jQuery.noConflict(); 
     $m(document).ready(function() { 
      $m('.menu').dbGeneratedMenu(); 
     }); 
    </script> 
</html> 

以下是我为菜单的CSS:

.menu, .menu ul 
{ 
    margin: 0; 
    padding: 0; 
    list-style-type: none; 
    position: relative; 
    line-height: 2.5em; 
} 
.menu a 
{ 
    text-decoration: none; 
} 
.menu > li 
{ 
    margin-left: 15px; 
} 
.menu > li:first 
{ 
    margin-left:0px!important; 
} 
.menu > li > a 
{ 
    padding: 0px 10px; 
    margin: 0; 
    width: 100%; 
    text-decoration: none; 
    color: #005D7C; 
    font-weight: bold; 
} 
div.box 
{ 
    position: absolute; 
    z-index: -1; 
    background-color: #75CDD2; 
    left: 0; 
    top: 0; 
    border-radius: 4px 4px 0px 0px; 
    -moz-border-radius: 4px 4px 0px 0px; 
    -webkit-border-radius: 4px 4px 0px 0px; 
} 
li.pull-down 
{ 
    padding-right:6px; 
} 
li.pull-down > a 
{ 
    background-image: url(/Images/menu/darrow.png); 
    background-position: 96% 75%; 
    background-repeat: no-repeat; 
    padding-right: 20px; 
} 
li.right-menu > a 
{ 
    background-image: url(/Images/menu/rarrow.png); 
    background-position: 97% 45%; 
    background-repeat: no-repeat; 
} 
.menu a.selected 
{ 
    background-color: #75CDD2; 
    border-radius: 0px 4px 4px 4px; 
    -moz-border-radius: 0px 4px 4px 4px; 
    -webkit-border-radius: 0px 4px 4px 4px; 
} 
.menu li 
{ 
    float: left; 
    position: relative; 
} 

.menu ul 
{ 
    position: absolute; 
    display: none; 
    width: 200px; 
    top: 2.5em; /*padding-right: 10px;*/ 
    background-color: #B8C402; /*-moz-opacity: .50;  filter: alpha(opacity=50);  opacity: .50;*/ 
    border-radius: 0px 4px 4px 4px; 
    -moz-border-radius: 0px 4px 4px 4px; 
    -webkit-border-radius: 0px 4px 4px 4px; 
} 

.menu li ul a 
{ 
    width: 180px; 
    height: auto; 
    float: left; 
    color: #FFFFFF; 
    padding: 0 10px; 
} 
.menu li ul li 
{ 
    padding: 0; 
    margin: 0; 
} 
.menu ul ul 
{ 
    top: auto; 
} 

.menu li ul ul 
{ 
    left: 198px; /*margin: 0px 0 0 10px;*/ 
} 
.menu-item-selected > a 
{ 
    background-color: #000000; 
    -moz-opacity: .50; 
    filter: alpha(opacity=50); 
    opacity: .50; 
    font-weight: bold; 
} 
a:hover { 
    background-color: #B8C402; 
    color: #FFFFFF !important; 
} 
.menu-item-selected > a:hover 
{ 
    background-color: #000000; 
    color: #FFFFFF !important; 
} 

这是JQuery的捣鼓数据库生成的菜单:

(function ($) { 
    $.fn.extend({ 
     dbGeneratedMenu: function() { 
      return this.each(function() { 
       //add class .drop-down to all of the menus having drop-down items 
       var menu = $(this); 
       var timeoutInterval; 
       if (!menu.hasClass('menu')) menu.addClass('menu'); 
       $("> li", menu).each(function() { 
        if ($(this).find("ul:first").length > 0) 
         $(this).addClass('pull-down'); 
       }); 

       $("> li ul li ul", menu).each(function() { 
        $(this).parent().addClass('right-menu'); 
       }); 
       $("li", menu).mouseenter(function() { 
        var isTopLevel = false; 
        //if its top level then add animation 
        isTopLevel = $(this).parent().attr('class') === 'menu'; 
        if (isTopLevel) { 
         clearTimeout(timeoutInterval); 
         var w = $(this).outerWidth(); 
         // if ($(this).hasClass('pull-down')) w += 10; 
         var h = $(this).outerHeight(); 
         var box = $('<div/>').addClass('box'); 
         $('> li', menu).removeClass('selected'); 
         $('>li div.box', menu).remove(); 
         $('>li ul', menu).css('display', 'none').slideUp(0); 
         $(this).prepend(box); 
         $(this).addClass('selected'); 
         box.stop(true, false).animate({ width: w, height: h }, 100, function() { 
          if ($(this).parent().find('ul:first').length == 0) { 
           timeoutInterval = setTimeout(function() { 
            box.stop(true, false).animate({ height: '+=5' }, 300, function() { 
             box.parent().find('ul:first').css('display', 'block').css('top', box.height()).stop(true, false).slideDown(100); 
            }); 
           }, 10); 
          } 
          else { 

           timeoutInterval = setTimeout(function() { 
            box.stop(true, false).animate({ height: '+=0' }, 0, function() { 
             box.parent().find('ul:first').css('display', 'block').css('top', box.height()).stop(true, false).slideDown(100); 
            }); 
           }, 10); 
          } 
         }); 
        } 
        else { 
         $(this).find('ul:first').css('display','block').stop(true, false).slideDown(100); 
        } 

       }).mouseleave(function() { 
        isTopLevel = $(this).parent().attr('class') === 'menu'; 
        if (isTopLevel) { 
         $(this).parent().find('div.box').remove(); 
        } 
        $(this).find('ul').slideUp(100, function() { 

         $(this).css('display', 'none'); 
        }); 
       }); 

       $('> li > ul li a', menu).hover(function() { 
        $(this).parent().addClass('menu-item-selected'); 
       }, function() { 

        $(this).parent().removeClass('menu-item-selected'); 
       }); 

      }); 
     } 
    }); 
})(jQuery); 

局部视图对于日期:

@model DateTime? 
@{ 
    var value = ""; 
    if (Model.HasValue) { 
     value = String.Format("{0:d}", Model.Value.ToString("dd-MM-yyyy")); 
    } 
} 
@Html.TextBox("", value, new { @class = "datefield", type = "date" }) 

型号:

public class LEAVE_REQUEST 
{ 
    [Display(Name = "Id"), Required, DatabaseGenerated(DatabaseGeneratedOption.None)] 
    public long ALLOTMENT_REQUEST_ID { get; set; } 

    [Display(Name = "Request date"), Required] 
    public Nullable<System.DateTime> REQUEST_DATE { get; set; } 

    [Display(Name = "Leave start date"), Required(ErrorMessage="Leave start date not entered")] 
    [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd-mm-yyyy}")] 
    public Nullable<System.DateTime> LEAVE_START_DATE { get; set; } 
} 

查看我在哪里实施的DateTimePicker

@model TESTAPP.Models.LEAVE_REQUEST 
@{ 
    ViewBag.Title = "Create"; 
} 
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script> 

@using (Html.BeginForm()) { 
    @Html.AntiForgeryToken() 

    <fieldset> 
     <legend>LEAVE_REQUEST</legend> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.LEAVE_START_DATE) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.LEAVE_START_DATE) 
      @Html.ValidationMessageFor(model => model.LEAVE_START_DATE, "*") 
     </div> 

     @Html.ValidationSummary(false) 
     <p> 
      <input type="submit" value="Submit" class="submitButton"/> 
     </p> 
    </fieldset> 
} 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

我真的很感激,从你们的任何帮助。谢谢

+0

您已经包含了'jquery-ui- {version} .js'两次(在使用'@ Scripts.Render(“〜/ bundles/jqueryui“)'并再次在视图中使用''。删除视图中的一个。 –

+0

不幸的是,没有做出任何区别:(。我仍然无法获取日期选择器 –

+0

你是什么意思_无法获得datepicker_ - 你的问题是关于你的菜单脚本为什么停止工作你已经发布了这么多不相关的代码很难想象任何人会我可以看到任何与使用日期选择器脚本有关的代码 –

我终于解决了我的问题。我认为JQuery包中的某些内容与我用于菜单导航的js文件相冲突。我只使用jquery-1.8.2.min.js而不是渲染整个bundle。现在它按预期工作。然而,我仍然无法找到与什么冲突:(