簡體   English   中英

jQuery在Dreamweaver中工作但不在瀏覽器中工作

[英]jQuery working in dreamweaver but not in browser

所以,這是我的代碼(不是全部,只是你需要理解的代碼):

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文件夾中,但對於一些pourposes,我粘貼了一個CDN。 如果我將所有內容上傳到jsfiddle並將javascript代碼放入javascript框中,它可以正常工作,但是從Dreamweaver中卻沒有。

嘗試這個

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" />
<script>
    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});
            });
        });

創建一個新文檔並將以下內容粘貼到其中:

$(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,然后將以下內容添加到頭部:

<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>

這應該可以解決問題。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM