gpt4 book ai didi

javascript - Draggable & Droppable 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:48 25 4
gpt4 key购买 nike

我遇到了 Draggable 和 Droppable 的问题,我尝试了很多代码,但似乎 Event 没有启动,

任何人在这里帮助我,请帮助我,我使用 JSON 数据文件来显示数据,我正在获取 html 页面上的所有数据,但只是拖放问题,我正在使用 netbeans 和 Chrome 浏览器(我没有广告拦截器)。

    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
table {
border-collapse:collapse;
}
table tr td {
border: 1px solid red;
padding:2px 15px 2px 15px;
width:auto;
}
#tabs ul li.drophover {
color:green;
}

</style>
<script>
$(document).ready(function () {

$("tr").draggable({
helper: "clone"
});

$("tr").droppable({
drop: function (event, ui) {


$(ui.draggable).remove();
$(ui.helper).remove();
}
});

});
</script>
<script type="text/javascript">
$.ajax({
type: 'GET',
dataType: "json",
url: 'data.json',
success: function (data) {
console.log("Data Received");
var bodyTag = document.getElementsByTagName("body")[0];
var h1Tag = document.createElement("h1");
h1Tag.setAttribute("id", "title");
h1Tag.innerHTML = "List Of Hotels : ";
bodyTag.appendChild(h1Tag);
//---------------------
var tableTag = document.createElement("table");
var tablebTag = document.createElement("tbody");
tableTag.setAttribute("id", "dragg");
// log the result of the data converted into a jquery object.
for (var i = 0; i < data.length; i++) {
var trTag = document.createElement("tr");
trTag.setAttribute("class", "hotellist");
var imgBlock = document.createElement("td");
imgBlock.setAttribute("class", "imgcell");
var thmbnlimg = document.createElement("img");
thmbnlimg.src = data[i].thumbnailUrl;
trTag.appendChild(imgBlock);
imgBlock.appendChild(thmbnlimg);
imgBlock.style.rowspan = "5";
var info = document.createElement("td");
var namedata = document.createElement("span");
namedata.innerHTML = data[i].name;
var addressdata = document.createElement("span");
addressdata.innerHTML = data[i].location.address.addressLine1;
var citydata = document.createElement("span");
citydata.innerHTML = data[i].location.address.cityName + data[i].location.address.zip;
var cntrydata = document.createElement("span");
cntrydata.innerHTML = data[i].location.address.countryName;
var phndata = document.createElement("span");
phndata.innerHTML = data[i].location.address.phone;
var starratingdata = document.createElement("span");
starratingdata.innerHTML = "Star Rating : " + data[i].starRating;
var reviewscoredata = document.createElement("span");
reviewscoredata.innerHTML = "Guest Rating : " + data[i].overallGuestRating;
var linkdata = document.createElement("span");
var link = document.createElement("a");
link.innerHTML = "View";
link.href = "http://maps.google.com/?q=" + data[i].location.latitude + "," + data[i].location.longitude;

linkdata.appendChild(link);

namedata.setAttribute("class", "name");
addressdata.setAttribute("class", "address");
citydata.setAttribute("class", "city");
cntrydata.setAttribute("class", "cntry");
phndata.setAttribute("class", "phone");
starratingdata.setAttribute("class", "star");
reviewscoredata.setAttribute("class", "review");

info.appendChild(document.createElement("br"));
info.appendChild(namedata);
info.appendChild(document.createElement("br"));
info.appendChild(addressdata);
info.appendChild(document.createElement("br"));
info.appendChild(citydata);
info.appendChild(document.createElement("br"));
info.appendChild(cntrydata);
info.appendChild(document.createElement("br"));
info.appendChild(phndata);
info.appendChild(document.createElement("br"));
info.appendChild(starratingdata);
info.appendChild(document.createElement("br"));
info.appendChild(reviewscoredata);
info.appendChild(document.createElement("br"));
info.appendChild(linkdata);
trTag.appendChild(info);
tablebTag.appendChild(trTag);
}
tableTag.appendChild(tablebTag);
bodyTag.appendChild(tableTag);
}
});
</script>
</head>
<body>

</body>

最佳答案

在您的 ajax 成功函数中准备好可拖动代码,而不是在 DOM 中准备好:


success: function (data) {
//other code
$("tr").draggable({
helper: "clone"
});

$("tr").droppable({
drop: function (event, ui) {


$(ui.draggable).remove();
$(ui.helper).remove();
}
};

关于javascript - Draggable & Droppable 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37772137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com