jQuery在dreamweaver中工作,但不在浏览器中 [英] jQuery working in dreamweaver but not in browser

查看:136
本文介绍了jQuery在dreamweaver中工作,但不在浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这里是我的代码(不是所有的,只是你需要了解):

So, here's my code(not all of it, just what you need to understand):

HTML:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
    jQuery(document).ready(function(){
                jQuery("nav ul ul").each(function(){
                    var navWidth=jQuery(this).width();
                    var liWidth=jQuery(this).closest("li").width();
                    var gaps=navWidth-liWidth;
                    var moveLeft=-gaps/2;
                    jQuery(this).css({"margin-left":moveLeft});

                })
            })
</script>
</head>
<body> 
<header>
    <nav>
          <ul><li>
            <a href="index.html">ACASA</a></li><li>
            <a href="cultura.html">CULTURA</a>
                <ul class="align1">
                    <li><a href="culturapopulara.html">Cultura populară</a></li>
                    <li class="border"><a href="culturaculta.html">Cultura cultă</a></li>
                    <li class="border"><a href="culturamasa.html">Cultura de masă</a></li>
                </ul>
            </li><li>
            <a href="cultura romaniei.html">CULTURA ROMÂNIEI</a>
                <ul class="align2">
                    <li><a href="elementedac.html">Elemente dacice</a></li>
                    <li class="border"><a href="elemrom.html">Elemente romane</a></li>
                    <li class="border"><a href="alte influente.html">Alte influențe</a></li>
                </ul>
            </li><li>
            <a href="interferente culturale.html">INTERFERENȚE CULTURALE</a>
                <ul class="align3">
                    <li><a href="romi.html">Români și romi</a></li>
                    <li class="border"><a href="maghiari.html">Români și maghiari</a></li>
                    <li class="border"><a href="evrei.html">Români și evrei</a></li>
                </ul>
            </li>
          </ul>
    </nav>   
</header>
</body>

CSS:

nav {
    text-align: center;
    margin-top: 5%;
    margin-bottom: 5%;
    font-family: Krona One;
    border-top: 1px solid #fff;
    text-decoration: none;
    color: #FFFFFF;
    font-size: large;

}
nav ul {
    list-style-type: none;
    position:relative;
}

nav ul li {
    display: inline-block;
    padding: 25px;
}

nav ul li a {
    color: #FFFFFF;
    text-decoration: none;
}


nav ul li a:hover {
    text-shadow: 0px 0px 20px #FFFFFF;
    color: #FFFFFF;
    text-decoration: none;  
}

nav ul li a:hover + ul{
    display: block;
    visibility:visible;
}

nav ul ul::before {
    background: url(images/menu_corner.gif) no-repeat 0% 0%;
    width: 9px;
    height: 5px;
    display: block;
    margin: 0 -5px 0 0;
    position: absolute;
    top: -5px;
    right: 50%;
    content: '';
}

nav ul ul {
    text-align: center;
    font-weight: normal;
    display: none;
    visibility: hidden;
    position: absolute;
    background-color: #2E2E2E;
    font-family: 'Open Sans', sans-serif;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 20px;
    padding-left: 0px;
    padding-right: 0px;
    margin-top: 30px;
    font-size: 16px;
}

nav ul ul li {
    display: block;
    padding-top: 10px;
    padding-right: 10px;
    padding-left: 10px;
    padding-bottom: 10px;
    margin-top: 5px;
    margin-bottom: 5px;
}

.border {
    border-top: 1px solid #434343;  
}

nav ul ul li a:hover {
    color: #767676;
    text-decoration: none;
    text-shadow: 0px 0px 0px;
}

body {
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    font-style: normal;
    font-weight: 400;
    background-image: url(http://i.imgur.com/qjincKZ.jpg);
    color: #FFFFFF;
    margin: 0 0 0 0;
    background-size: cover;
}



我不知道为什么,但jQuery只在dreamweaver中工作。 。为了在dreamweaver中工作,我必须下载jQuery并将其添加到contains文件夹,但对于某些情况,我粘贴了一个CDN。
如果我将所有内容上传到jsfiddle并将javascript代码放入javascript框,它的工作原理,但是从dreamweaver它不是。

I don't know why, but the jQuery works only in dreamweaver... In order to work in dreamweaver, I have to download jQuery and add it to the contain folder, but for some pourposes, I pasted a CDN. If I upload everything to jsfiddle and put the javascript code into the javascript box, it works, but from dreamweaver it doesn't.

推荐答案

创建一个新文档并将其粘贴到其中:

Create a new document and paste the following inside it:

$(document).ready(function () {
    $("nav ul ul").each(function () {
        var navWidth = $(this).width();
        var liWidth = $(this).closest("li").width();
        var gaps = navWidth - liWidth;
        var moveLeft = -gaps / 2;
        $(this).css({
            "margin-left": moveLeft
        });

    });
});

接下来,将其作为global.js保存在您的contains文件夹中,然后将以下内容添加到头文件中:

Next, save it as global.js inside your contain folder and then add the following to the head:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="contain/global.js"></script>

这应该可以做到。
希望这有帮助。

This should do the trick. Hope this helps.

这篇关于jQuery在dreamweaver中工作,但不在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆