简体   繁体   中英

Changing the draggable attribute

I am making an maths puzzle page for kids. The answers are in s which drag over the questions. When an answer is used, I would like to disable the dragging of the specific answer. I can "dim" the answer and prevent it from being dropped but thus far have found no way of preventing the from being dragged.

Please help.... I would prefer not to use JQuery if possible

function handledrop(elt, evt) {

        //Dim THE DRAGGED ITEM 
        dragitem.style.opacity=0.4;  //***********This works
        dragitem.style.hidden="true";//***********This doesn't or any variation I an think of
                                     //***********dragitem.draggable="false"
                                     //***********dragitem.style.draggable="false"
                                     //***********dragitem.draggable="false"

        dragitem.ondrag =  "donothing()";
        dragitem.ondragstart="donothing()" ;
        }

您可以将draggable设置为false为

document.getElementById('you_id').setAttribute('draggable', false);

Try using:

function handledrop(elt, evt) {

        //Dim THE DRAGGED ITEM 
        dragitem.style.opacity=0.4;  //***********This works
        dragitem.ondrag =  "return false;";
        dragitem.ondragstart="return false;" ;
}

In this you'll prevent the drag function previously set on the element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM