获取在if语句中被拖动的元素的ID

时间:2019-02-21 03:40:07

标签: javascript

嗨,我正在尝试找到一种方法来确定要拖动哪些元素,这会影响插入的结果。如果要选择金色img,我想添加一个类,如果要选择银色img,我想添加另一个类。我以为这样的事情可能行得通,但不行...

 function GoldDragStart(event) {
      event.dataTransfer.setData("Text", event.target.id);
      var Type = "Gold";
    }


 function SilverDragStart(event) {
      event.dataTransfer.setData("Text", event.target.id);
      var Type = "Silver";
    }



 function allowDrop(event) {
      event.preventDefault();
    }


function Img_1_Drop(event) {
    if (Type == "Gold") {   
        document.getElementById('GoldSelection').classList.add('GoldSelection1');
            var pic = "https://i.imgur.com/m2NhQQB.png";
            document.getElementById('GoldSelection').src = pic.replace('90x90', '225x225');
            document.getElementById('GoldSelection').style.display='block'; 
    } else if (Type == "Silver") {


document.getElementById('SilverSelection').classList.add('SilverSelection1');
            var pic = "https://i.imgur.com/RevL021.png";
            document.getElementById('SilverSelection').src = pic.replace('90x90', '225x225');
            document.getElementById('SilverSelection').style.display='block';  
    } 
}

0 个答案:

没有答案