Javascript 无法加载
Javascript could not load
我做错了什么? Javascript 无效。 jsfiddle 有 link,它运行良好:http://jsfiddle.net/onazdce2/ .
我想以某种方式将它重写到我的程序中,但 js 似乎没有加载。
HTML:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Drag & Drop rubriky</title>
<link href="style.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="launchPad">
<div class="card">apple</div>
<div class="card">orange</div>
<div class="card">banana</div>
<div class="card">car</div>
<div class="card">bus</div>
</div>
<div id="dropZone">
<div class="stack">
<div class="stackHdr">title 1 here </div>
<div class="stackDrop1"></div>
</div>
<div class="stack">
<div class="stackHdr">title 2 here</div>
<div class="stackDrop2"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
JS:
// JavaScript Document
$("#launchPad").height($(window).height() - 20);
var dropSpace = $(window).width() - $("#launchPad").width();
$("#dropZone").width(dropSpace - 10);
$("#dropZone").height($("#launchPad").height());
$(".card").draggable({
appendTo: "body",
cursor: "move",
helper: 'clone',
revert: "invalid",
});
$("#launchPad").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$("#launchPad").append($(ui.draggable));
}
});
$(".stackDrop1").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
}
});
$(".stackDrop2").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
}
});
CSS:
/* CSS Document */
body {
margin: 0;
}
#launchPad {
float:left;
border: 1px solid #eaeaea;
background-color: #f5f5f5;
}
#dropZone {
float:right;
border: 1px solid #eaeaea;
background-color: #ffffcc;
}
.card {
width: 150px;
padding: 5px 10px;
margin:5px;
border:1px solid #ccc;
background-color: #eaeaea;
}
.stack {
width: 180px;
border: 1px solid #ccc;
background-color: #f5f5f5;
margin: 20px;
}
.stackHdr {
background-color: #eaeaea;
border: 1px solid #fff;
padding: 5px
}
.stackDrop1, .stackDrop2 {
min-height:100px;
padding: 15px;
}
.stack .card.ui-draggable{
background-color:orange;
height:150px;
}
我认为你没有在你的代码中添加 Jquery UI 脚本参考 在你的 head 标签中添加以下脚本希望它能工作
<script src="http://code.jquery.com/ui/1.12.0/jquery-
ui.min.js"integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
crossorigin="anonymous"></script>
根据 fiddle 添加这个后,一切正常。
已解决:我必须在 head 标记中同时引用两个脚本。谢谢大家的指点。
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous"></script>
我做错了什么? Javascript 无效。 jsfiddle 有 link,它运行良好:http://jsfiddle.net/onazdce2/ .
我想以某种方式将它重写到我的程序中,但 js 似乎没有加载。
HTML:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Drag & Drop rubriky</title>
<link href="style.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="launchPad">
<div class="card">apple</div>
<div class="card">orange</div>
<div class="card">banana</div>
<div class="card">car</div>
<div class="card">bus</div>
</div>
<div id="dropZone">
<div class="stack">
<div class="stackHdr">title 1 here </div>
<div class="stackDrop1"></div>
</div>
<div class="stack">
<div class="stackHdr">title 2 here</div>
<div class="stackDrop2"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
JS:
// JavaScript Document
$("#launchPad").height($(window).height() - 20);
var dropSpace = $(window).width() - $("#launchPad").width();
$("#dropZone").width(dropSpace - 10);
$("#dropZone").height($("#launchPad").height());
$(".card").draggable({
appendTo: "body",
cursor: "move",
helper: 'clone',
revert: "invalid",
});
$("#launchPad").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$("#launchPad").append($(ui.draggable));
}
});
$(".stackDrop1").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
}
});
$(".stackDrop2").droppable({
tolerance: "intersect",
accept: ".card",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
}
});
CSS:
/* CSS Document */
body {
margin: 0;
}
#launchPad {
float:left;
border: 1px solid #eaeaea;
background-color: #f5f5f5;
}
#dropZone {
float:right;
border: 1px solid #eaeaea;
background-color: #ffffcc;
}
.card {
width: 150px;
padding: 5px 10px;
margin:5px;
border:1px solid #ccc;
background-color: #eaeaea;
}
.stack {
width: 180px;
border: 1px solid #ccc;
background-color: #f5f5f5;
margin: 20px;
}
.stackHdr {
background-color: #eaeaea;
border: 1px solid #fff;
padding: 5px
}
.stackDrop1, .stackDrop2 {
min-height:100px;
padding: 15px;
}
.stack .card.ui-draggable{
background-color:orange;
height:150px;
}
我认为你没有在你的代码中添加 Jquery UI 脚本参考 在你的 head 标签中添加以下脚本希望它能工作
<script src="http://code.jquery.com/ui/1.12.0/jquery-
ui.min.js"integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
crossorigin="anonymous"></script>
根据 fiddle 添加这个后,一切正常。
已解决:我必须在 head 标记中同时引用两个脚本。谢谢大家的指点。
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous"></script>