|
|
|
สอบถามเกี่ยวกับการ Drag Item และการแสดงค่าจาก DB ของแต่ละ Item ที่ถูก Drag |
|
|
|
|
|
|
|
ลองดูตัวอย่างครับ
Code (JavaScript)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
#box1 {width: 400px; height: 200px; background-color: #212121; }
ul{list-style: none; padding: 0px;}
li{ display: inline; pading: 5px; background-color: #424242; cursor: pointer; color: white; }
</style>
<script language="JavaScript">
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function allowDrop(ev) {
ev.preventDefault();
}
function drop(ev){
ev.preventDefault();
var drag_id=ev.dataTransfer.getData("text");
document.getElementById('drop_id').innerHTML = ev.target.id;
document.getElementById('drag_id').innerHTML = drag_id;
document.getElementById('target_box').appendChild(document.getElementById(drag_id));
}
function calc(){
var lis = document.getElementById('target_box').childNodes;
var vl = new Array;
if( lis.length){
var total = 0;
for(var i=0; i<lis.length; i++){
vl[i] = parseInt(lis[i].getAttribute('value'));
total += vl[i];
}
document.getElementById('cal').innerHTML = total;
}
}
</script>
</head>
<body>
<form>
<ul id=source_box >
<li data-draggable="item" align = "center" id="sci" value="15" draggable="true" ondragstart="drag(event)">Scientific</li>
<li data-draggable="item" align = "center" id="art" value="20" draggable="true" ondragstart="drag(event)">Artistic</li>
<li data-draggable="item" align = "center" id="eng" value="30" draggable="true" ondragstart="drag(event)">Language</li>
</ul>
<div data-draggable="target" id="box1" ondrop="drop(event)" ondragover="allowDrop(event)">
<ul id=target_box></ul>
</div>
<h1><button type=button id="calculate" onclick="calc()">=</button></h1>
<p name="cal" id="cal"></p>
</form>
Drag ID = <b id=drag_id></b><br>
Drop ID = <b id=drop_id></b>
</body>
</html>
|
ประวัติการแก้ไข 2016-02-05 06:55:55 2016-02-05 07:03:38 2016-02-05 07:05:26
|
|
|
|
Date :
2016-02-05 06:53:20 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะคะ
|
|
|
|
|
Date :
2016-02-05 12:22:43 |
By :
jarainland |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|