我有这个JS脚本:
// JavaScript Document
var items_left = [];
var items_right = [];
function addTrade(left, object) {
if(left === "true"){
if(items_left.length < 4){
items_left.push($(object).attr("data-id"));
console.log(items_left.length);
$(object).attr("onClick", "removeTrade(\"true\", this);");
$( "#addtrade_have" ).append($(object))
}
} else {
if(items_right.length < 4){
items_right.push($(object).attr("data-id"));
console.log(items_right.length);
$(object).attr("onClick", "removeTrade(\"false\", this);");
$( "#addtrade_want" ).append($(object));
}
}
}
function submit() {
console.log("Submit called!");
var comment = document.getElementById("comment").value;
if(items_left.length > 0 && items_right.length > 0){
var data_post = {comment: comment, h_1: items_left.shift(), h_2: items_left.shift(), h_3: items_left.shift(), h_4: items_left.shift(), w_1: items_right.shift(), w_2: items_right.shift(), w_3: items_right.shift(), w_4: items_right.shift()};
console.log(data_post);
$.ajax({
type: "POST",
url: "trade_insert.php",
data: data_post,
success: function(){
alert("Trade sent!");
window.location.replace("mytrades.php");
},
error: function(){
alert("ERROR!");
}
});
} else {
alert("You must add at least 1 item to each side!");
}
}
PHP脚本:
<div id="addtrade_have"></div>
<div id="addtrade_want"></div>
<div class='skin'>
<div class='skin-item' data-id='".$item_id."'>
<img onmouseover=\"nhpup.popup('<b>".$item_name." (".$exterior.")</b><br>".$rarity."');\" src='http://steamcommunity-a.akamaihd.net/economy/image/".$icon_url."/99fx66f' alt='Picture not found!' class='img' onClick=\"addTrade('true', this);\">
</div>
</div>
现在脚本执行此操作时,当我单击图像时,图像移动到ID #addtrade_have但我有除图像之外的div。当我点击图像时我怎么能这样做它会移动div和我的图像元素?
谢谢你们!