【问题标题】:Javascript not working from masterpageJavascript无法从母版页工作
【发布时间】:2013-11-28 00:51:09
【问题描述】:

我有一个母版页和一个 JS 文件,我在母版页中添加了指向 javascript 文件的链接,但是在使用母版页的任何页面上,JS 都不起作用。

我已经在一个单独的页面中单独尝试了代码并且它可以工作。

<head runat="server">
    <title></title>

    <link href="../styles/StyleSheet1.css" rel="stylesheet" />
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script src="../Scripts/Menu.js"></script>

    <script type="text/javascript">

        function openNewWin(url) {
            var x = window.open(url, 'mynewwin', 'toolbar=no,directories=no,location=no,menubar=no,left=0,top=0,resizable=no,status=no');
            x.focus();
        }
    </script>



</head>

菜单.JS:

$(function () {
    //When opening the page all level 2 and level 3 items must be hidden.
    $(function () {
        hideitems();
    })

    function hideitems() {
        $('h10').hide();
        $('h11').hide();
        $('h12').hide();
        $('h13').hide();
    }
    //Financial Click
    $('h7').click(function () {
        hideitems();
            $('h10').slideToggle();
            $('h11').slideToggle();
            $('h12').slideToggle();
        });
    //Container Click
        $('h8').click(function () {
            hideitems();;
            $('h13').slideToggle();
        });
    })

【问题讨论】:

  • 不工作怎么办?有什么错误吗?
  • 仅供参考:您在点击处理程序中添加点击处理程序。这不是一个好主意。
  • 没有错误,但功能不起作用。菜单项应该隐藏加载,然后您可以通过单击它们来修改它们,但它们什么也不做。
  • 这可能是路径问题,在渲染的页面上查看源代码,找到创建的完整路径,然后将其剪切并粘贴到浏览器中.. 如果你得到 404,你知道路径错了
  • 它不会在标记中创建路径,它只是 /Scripts/menu.js

标签: c# javascript jquery asp.net


【解决方案1】:

我认为是文件路径问题。你能按照这里给出的步骤操作吗

ASP.Net Master Page and File path issues

【讨论】:

  • 我已经看过那个帖子了,当我使用脚本管理器时它说它无效,并且对于查找路径它给出了一个无效字符错误。
【解决方案2】:

如前所述是路径问题。

您确定文件夹是 Scripts 而不是 scripts?

打开inspector并获取引用的链接,也可能你会在控制台中得到一个错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多