1
如果我在csets.php頁面中拖動,我可以拖放項目。但是,當我使用onchange來更改類別項目。 $ AJAX之後的新項目和查詢無法拖動。
Csets.php
<div class="wrapper">
<div id="options">
<?php
$strSQL = "SELECT * FROM item_head ORDER BY ihead_id DESC";
$objQuery = mysqli_query($con, $strSQL);
while($row = mysqli_fetch_array($objQuery)){
?>
<img width="150" height="120" src="item_head/<?php echo $row['filesName'];?>" id="drag1<?php echo $row['head_id'];?>" class="drag"</img>
<?php } ?>
</div>
</div>
的JavaScript
function selectCa(){
var xmlhttp=new XMLHttpRequest();
var value = document.getElementById("sel1").value;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("options").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "checkQuery.php?value="+value, true);
xmlhttp.send();
}
CheckQuery.php
<?php
$value = $_GET["value"];
//query head items
if($value == "head"){
$strSQL = "SELECT * FROM item_head ORDER BY ihead_id DESC";
$objQuery = mysqli_query($con, $strSQL);
while($row = mysqli_fetch_array($objQuery)){ ?>
<img width="150" height="120" src="item_head/<?php echo $row['filesName'];?>" id="drag1<?php echo $row['head_id'];?>" class="drag"></img>
<?php }
}else if($value == "body"){
$strSQL = "SELECT * FROM item_body ORDER BY ibody_id DESC";
$objQuery = mysqli_query($con, $strSQL);
while($row = mysqli_fetch_array($objQuery)){
?>
<img width='150' height='120' src='item_body/<?php echo $row['filesName'];?>' id='drag1' class='drag'></img>
<?php
}
}else if($value == "shoes"){
$strSQL = "SELECT * FROM item_shoes ORDER BY ishoes_id DESC";
$objQuery = mysqli_query($con, $strSQL);
while($row = mysqli_fetch_array($objQuery)){
?>
<img width='150' height='120' src='item_shoes/<?php echo $row['filesName'];?>' id='drag1' class='drag'></img>
<?php }
}
?>
如何重新啓動拖動函數? – tualek2221 2015-02-23 09:22:42
你目前如何讓你的元素可拖動?大概在頁面加載時運行一個函數來使所選元素可拖動。在AJAX完成後記得那個函數。 – Polarize 2015-02-23 09:25:15
我使用myFunction()來選擇元素拖放到selectCa()函數中,但它無法工作。 – tualek2221 2015-02-23 10:09:09