このコードをループなどで単純化する方法はありますか? 私は JavaScript の初心者で、私のコードはひどいものです。jqueryなどに変換するように言わないでください。
function dragLeftdropLeft1(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topLeft1').style.display = "none";
document.getElementById('topLeft2').style.display = "block";
}
function dragLeftdropLeft2(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topLeft2').style.display = "none";
document.getElementById('topLeft3').style.display = "block";
}
function dragLeftdropLeft3(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topLeft3').style.display = "none";
document.getElementById('topLeft4').style.display = "block";
}
function dragLeftdropLeft4(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topLeft4').style.display = "none";
document.getElementById('topLeft5').style.display = "block";
}
function dragLeftdropLeft5(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topLeft5').style.display = "none";
document.getElementById('topLeft1').style.display = "block";
}
function dragLeftdropRight1(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topRight1').style.display = "none";
document.getElementById('topRight2').style.display = "block";
}
function dragLeftdropRight2(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topRight2').style.display = "none";
document.getElementById('topRight3').style.display = "block";
}
function dragLeftdropRight3(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topRight3').style.display = "none";
document.getElementById('topRight4').style.display = "block";
}
function dragLeftdropRight4(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topRight4').style.display = "none";
document.getElementById('topRight5').style.display = "block";
}
function dragLeftdropRight5(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
document.getElementById('topRight5').style.display = "none";
document.getElementById('topRight1').style.display = "block";
}
function dragRightdropLeft1(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topLeft1').style.display = "none";
document.getElementById('topLeft2').style.display = "block";
}
function dragRightdropLeft2(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topLeft2').style.display = "none";
document.getElementById('topLeft3').style.display = "block";
}
function dragRightdropLeft3(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topLeft3').style.display = "none";
document.getElementById('topLeft4').style.display = "block";
}
function dragRightdropLeft4(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topLeft4').style.display = "none";
document.getElementById('topLeft5').style.display = "block";
}
function dragRightdropLeft5(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topLeft5').style.display = "none";
document.getElementById('topLeft1').style.display = "block";
}
function dragRightdropRight1(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topRight1').style.display = "none";
document.getElementById('topRight2').style.display = "block";
}
function dragRightdropRight2(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topRight2').style.display = "none";
document.getElementById('topRight3').style.display = "block";
}
function dragRightdropRight3(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topRight3').style.display = "none";
document.getElementById('topRight4').style.display = "block";
}
function dragRightdropRight4(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topRight4').style.display = "none";
document.getElementById('topRight5').style.display = "block";
}
function dragRightdropRight5(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Right");
document.getElementById('topRight5').style.display = "none";
document.getElementById('topRight1').style.display = "block";
}
コードの動作を見たい場合は、http://thomaswd.com/chopsticksで完全な HTML コードを見ることができます。HTMLとjavascriptを使って箸ゲームを作ろうとしています。
ありがとう!