我已经在通过拖放操作传送“id”。但我想转移第二个属性“name”。这可能吗?如果可能,我将如何在代码中更改它

function drag_start(event) {
    _('app_status').innerHTML = "Dragging the "+event.target.getAttribute('id');
    event.dataTransfer.dropEffect = "move";
    event.dataTransfer.setData("text", event.target.getAttribute('id') );
    event.dataTransfer.setData("text", event.target.getAttribute('name') );
}

function drag_drop(event) {
    event.preventDefault();
    var hr = new XMLHttpRequest();
    var url = "test_parse_example.php";

    var elem_id = event.dataTransfer.getData("text");
    var name = event.dataTransfer.getData("text");

    var event_id = event.target.getAttribute('id');
    var value = event.target.getAttribute('value');
    var time = document.getElementById("display").innerHTML = displayHours + ":" + displayMinutes + ":" + displaySeconds;
    var vars = "elem_id="+elem_id+"&event_id="+event_id+"&value="+value+"&time="+time+"&name="+name;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("status").innerHTML = return_data;
        }
    }

    hr.send(vars);
}

最佳答案

event.dataTransfer.setData("text", event.target.getAttribute('id') );
event.dataTransfer.setData("text1", event.target.getAttribute('name') );


var elem_id = event.dataTransfer.getData("text");
var name = event.dataTransfer.getData("text1");

10-06 08:13