我为简单的拖放编辑器编写了一个代码。它有3个面板,我将项目从第一个面板拖到第二个面板,拖动项目的内容显示在第3个面板中。代码位于:https://jsfiddle.net/tek0rfsw/
全屏结果显示在:http://jsfiddle.net/tek0rfsw/embedded/result/
javaScript代码:
$(document).ready(function() {
$('#remittanceId').hide();
$('#goldId').hide();
//alert("caling");
/*
var $this = $(this);
alert("caling2222");
$("#remittanceId").css("display", "");
$("#remittanceId").css("display", "block"); */
});
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
//alert($('#drag1').text());
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
// var id = $('#drag1').text();
var value = $(ev).text();
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
var id = $('#' + data).text().replace(/\s/g, '');
//alert(id);
/* if (id == "1)Remittence") {
alert('remitt');
var remHead = $('#remId').text().replace(/\s/g, '');
document.getElementById("featureHead").innerHTML = remHead;
var div = document.createElement('div');
div.className = 'row';
div.innerHTML = '<div class="container"><select name="dropdown" class="selectpicker" id="fromCurrencyId"><option value="0" selected>Select From Currency</option><!-- <option value="MYR">MYR-</option> --><option value="MYR">AED-DIRHAM</option><option value="USD">USD-US DOLLAR</option></select> → <select name="dropdown" class="selectpicker" id="toCurrencyId" onchange="checkFromCurrency()"><option value="0" selected>Select To Currency</option><option value="INR">INR-INDIAN RUPEE</option></select> <br><br> <input type="submit" class="btn btn-primary" value="Clear" onclick="remittanceClear()" /> <input type="submit" class="btn btn-primary" value="Save" onclick="remittanceSave()" /></div>';
document.getElementById('featureBody').appendChild(div);
return 0;
} */
if (id == "2)AssetGold") {
//alert('sdzhx');
errorShow();
ev.preventDefault();
return false;
} else {
/* error(); */
var remHead = $('#remId').text().replace(/\s/g, '');
document.getElementById("featureHead").innerHTML = remHead;
var div = document.createElement('div');
div.className = 'row';
div.innerHTML = '<div class="container"><select name="dropdown" class="selectpicker" id="fromCurrencyId"><option value="0" selected>Select From Currency</option><!-- <option value="MYR">MYR-</option> --><option value="MYR">AED-DIRHAM</option><option value="USD">USD-US DOLLAR</option></select> → <select name="dropdown" class="selectpicker" id="toCurrencyId" onchange="checkFromCurrency()"><option value="0" selected>Select To Currency</option><option value="INR">INR-INDIAN RUPEE</option></select> <br><br> <input type="submit" class="btn btn-primary" value="Clear" onclick="remittanceClear()" /> <input type="submit" class="btn btn-primary" value="Save" onclick="remittanceSave()" /></div>';
document.getElementById('featureBody').appendChild(div);
return false;
}
if (id == "3)CrudeOil") {
ev.preventDefault();
return false;
}
}
/* function show(ev) {
ev.preventDefault();
var newID = ev.dataTransfer.getData("id");
alert(id);
} */
function assetClear() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, clear it!",
closeOnConfirm: false
},
function() {
swal("Cleared!", "Your imaginary file has been cleared.",
"success");
});
}
function remittanceClear() {
swal({
title: "Are you sure?",
text: "You will not be to save the values!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, clear it!",
closeOnConfirm: false
}, function() {
swal("Cleared!", "Your values are cleared.", "success");
});
}
function saveAsset() {
swal("Good!", "Asset Details Added Successfully.", "success");
}
function remittanceSave() {
swal("Good!", "Remittance Details Added Successfully.", "success");
}
function error() {
swal('Oops...',
'Something went wrong! Please contact the adminisrator',
'error');
}
function errorShow() {
swal('Oops...', 'Not allowed. You can use one feature at a time',
'error');
}
当我在浏览器中运行代码时,出现此错误:ReferenceError: drag is not defined
。我错过了什么?