簡體   English   中英

Javascript可在Jsfiddle上運行,但不能在Dreamweaver上運行,無法獲取語法錯誤,意外的令牌等

[英]Javascript working on Jsfiddle but not on dreamweaver, getting uncaught syntaxerror unexpected token and the like

這是我正在做的事的示例http://jsfiddle.net/ep39v/78/ ,框架是Minko Gechev給我的

它在Jsfiddle上完美運行,但是我不知道為什么它不會轉移到Dreamweaver,這些是我當前的文件:

的HTML

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/MattyScript.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="Style.css" />
</head>

<body>
<button id="showFormBtn">Show form</button>
<div class="form"></div>
<div class="box"></div>
<script>
positionForm();
</script>
</body>

JAVASCRIPT

(function($){
var form = $('.form');
var form2 = $('.box');


function positionForm() {
    form.css({
        top: -form.height(),
        left: ($(document.body).width() - form.width()) / 2
    });
}

function addListeners(background) {
    background.click(function() {
        background.fadeOut(300, function() {
            background.remove();
        });
        form.animate({
            top: -form.height() - 10
        }, 300);
        form2.animate({
            left: '100%'
        }, 300);
        setTimeout(function() {
            form2.css('display', 'none');
        }, 301);
    });
}

function showForm() {
    var form = $('.form');
    var form2 = $('.box');
    positionForm();
    form2.css('display', 'block');
    form.animate({
        top: 10
    }, 1500, 'easeOutElastic');
    form2.animate({
        left: '50%'
    }, 1500, 'easeOutElastic');
}

function fadeBackground(callback) {
    var background = $('<div class="background"></div>');
    $(document.body).append(background);
    background.fadeTo(300, 0.5, function() {
        if (typeof callback === 'function') {
            callback();
        }
    });
    addListeners(background);
}

$('#showFormBtn').click(function() {
    fadeBackground(showForm);
});

form.click(function(e) {
    e.stopImmediatePropagation();
});

positionForm()})(jQuery);;

的CSS

@charset "utf-8";
/* CSS Document */
.form {
    width: 30%;
    height: 40%;
    background: black;
    position: absolute;
    z-index: 20;
}

.box {
    position: absolute;
    width: 50%;
    height: 300px;
    line-height: 300px;
    font-size: 50px;
    text-align: center;
    border: 2px solid black;
    left: 150%;
    display:none;
    top: 100px;
    margin-left: -25%;
}
body {
    height: 100%;
}
.background {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    background: black;
    opacity: 0;
    z-index: 10;
}​

救命!

如果您從jsfiddle中剪切並粘貼了代碼,則很有可能在代碼的末尾拾取了一些垃圾字符。

刪除最后兩行,然后手動鍵入。

暫無
暫無

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

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