Jquery 如何多次运行可拖放函数
到目前为止,我有两张图片(一男一女)可以拖动。当我拖动男人时,我希望可拖放的图像变为男人,女人也变为男人。到目前为止,它还可以工作,但假设我已经将可拖放图像更改为一个男人。然后,当我把这个女人拖过来时,它不会切换到一个女人的形象。它只会粘贴到它更改的第一个图像,我希望用户能够多次拖动和更改图像Jquery 如何多次运行可拖放函数,jquery,jquery-ui,drag-and-drop,jquery-ui-draggable,jquery-ui-droppable,Jquery,Jquery Ui,Drag And Drop,Jquery Ui Draggable,Jquery Ui Droppable,到目前为止,我有两张图片(一男一女)可以拖动。当我拖动男人时,我希望可拖放的图像变为男人,女人也变为男人。到目前为止,它还可以工作,但假设我已经将可拖放图像更改为一个男人。然后,当我把这个女人拖过来时,它不会切换到一个女人的形象。它只会粘贴到它更改的第一个图像,我希望用户能够多次拖动和更改图像 <div class="types"> <h1>TWO TYPES OF HARRASSMENT</h1> <p>Click and
<div class="types">
<h1>TWO TYPES OF HARRASSMENT</h1>
<p>Click and drag the employees to reveal more information.</p>
<img class="draggable-woman" src="images/drag-woman.png" />
<img class="draggable-man" src="images/drag-man.png" />
</br>
<div class="types-child">
<img class="quid" src="images/quid-empty.png" />
<div class="changeable-text"></div>
<img class="hostile" src="images/hostile-empty.png" />
</div>
</div>
<script>
$(".draggable-woman").draggable({
helper: "clone"
});
$(".draggable-man").draggable({
helper: "clone"
});
$(".quid").droppable({
drop: function( event, ui ) {
if ($(ui.draggable).hasClass("draggable-woman")){
$(this).replaceWith("<img class='quid' src='images/quid-withwoman.png'>");
} else {
$(this).replaceWith("<img class='quid' src='images/quid-withman.png'>")
}
}
});
</script>
两种类型的耙
单击并拖动员工以显示更多信息
$(“.draggable woman”).draggable({
助手:“克隆”
});
美元(“.draggable人”)。draggable({
助手:“克隆”
});
美元(“.quid”)。可拖放({
drop:函数(事件、用户界面){
if($(ui.draggable.hasClass(“可拖动的女人”)){
$(此)。替换为(“”);
}否则{
$(此)。替换为(“”)
}
}
});
只需重新处理事件。这可能对您有用:
$(".draggable-woman").draggable({
helper: "clone"
});
$(".draggable-man").draggable({
helper: "clone"
});
function handleQuidClass(){
$(".quid").droppable({
drop: function( event, ui ) {
if ($(ui.draggable).hasClass("draggable-woman")){
$(this).replaceWith("<img class='quid' src='images/quid-withwoman.png'>");
} else {
$(this).replaceWith("<img class='quid' src='images/quid-withman.png'>")
}
handleQuidClass();
}
});
}
handleQuidClass();
$(“.draggable woman”).draggable({
助手:“克隆”
});
美元(“.draggable人”)。draggable({
助手:“克隆”
});
函数handleQuidClass(){
美元(“.quid”)。可拖放({
drop:函数(事件、用户界面){
if($(ui.draggable.hasClass(“可拖动的女人”)){
$(此)。替换为(“”);
}否则{
$(此)。替换为(“”)
}
handleQuidClass();
}
});
}
handleQuidClass();