简体   繁体   English

视图具有_Layout,但下拉菜单不起作用

[英]View has _Layout but dropdown menu isn't working

I have a view that is using the Shared _Layout which has all of the stylesheets and javascript files referenced. 我有一个使用Shared _Layout的视图,该视图具有引用的所有样式表和javascript文件。

On my navbar I have a dropdown-menu : 在我的导航dropdown-menu我有一个dropdown-menu

<a class="dropdown-toggle" role="button" aria-expanded="false" href="#" data-toggle="dropdown">Navigate<span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuDivider">

But when I click on the dropdown, nothing happens.. the menu isn't displayed or anything. 但是,当我单击下拉列表时,没有任何反应。菜单未显示或任何其他内容。 When I click on the dropdown and move the cursor away the focus stays on the dropdown menu but again, nothing shows.. 当我单击下拉列表并将光标移开时,焦点停留在下拉菜单上,但再次没有显示。

It looks like this: 看起来像这样:

在此处输入图片说明

This dropdown works on every other View except this one. 此下拉菜单适用于除此视图之外的所有其他视图。

I have checked the View Source and all of the stylesheets & Javascript files from the _Layout are there. 我已经检查了View Source,并且_Layout中的所有样式表和Javascript文件都在那里。

This view gets created from an ajax call on another view: 此视图是通过另一个视图上的ajax调用创建的:

<script type="text/javascript">
$('#SendToController').on('click', function() {
    sendToController();
    return false;
});
function sendToController(){
    var selectedM = $('#M').val();
    var chosenY = $('#Y').val();
    var chosenC = $('#C').val();
    $.ajax({
        url: '/ALog/MReports/Generate',
        data: { 'mValue' : selectedM, 'y' : chosenY, 'c' : chosenC },
        type: 'GET',
        cache: false,
        success: function (data) {
            $("body").html(data);
        },
    });
}


</script>

Any help is appreciated. 任何帮助表示赞赏。

After your Ajax call the JS is not listening your new content, that why it's not working. 在您的Ajax调用之后,JS没有监听您的新内容,这就是为什么它不起作用的原因。 You should "reload" your function after $("body").html(data); 您应该在$("body").html(data);之后“重新加载”函数$("body").html(data); you can put $('.dropdown-toggle').dropdown(); 您可以放入$('.dropdown-toggle').dropdown(); to make your dropdown menu working. 使下拉菜单正常工作。

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

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