2013-03-18 109 views
0

我想使用jQuery重新調整大小並拖動div,獲取新的位置和維度,然後發佈到數據庫。問題是,它不會重新大小,請大家幫忙使用JQuery調整大小不起作用

這裏是代碼...

<html>  
<head> 
<title>resize</title> 
<script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> 


<script type="text/javascript"> 
    //Global variables 
    var request,height,width,xpos,ypos,specs; 
    //Ajax lines 

    function getRequestData()//determine the browser 
    { 
     if(window.ActiveXObject){request=new  ActiveXObject('Microsoft.XMLHTTP');} 
     if(window.XMLHttpRequest){request=new XMLHttpRequest();} 
     else{alert('Your Browser is not AJAX enabled');request=null;} 
     return request; 
    } 

    function sendIt(specs) 
    { 
     request=getRequestData(); 
     data="d="+specs; 
     request.open("POST","post.php",true); 
     request.setRequestHeader('Content-Type','application/x-www-form- urlencoded'); 
     request.send(data); 
    } 

    /*request.onreadystatechange=function() 
    { 
     if((request.readyState==4)&&request.status==200) 
     { 

     } 
    }*/ 

    function drag() 
    { 
     $('#prototype').draggable 
     (
      { 
       containment:'document', 
       cursor:'move', 
       stop:getPos 
      } 
     ); 
     $('#prototype').resizable 
     (
      { 
       containment:'document', 
       stop:getDimension 
      } 
     ); 
    } 



    function getPos(event,ui) 
    { 
     xpos=parseInt(ui.offset.left); 
     ypos=parseInt(ui.offset.top); 
      specs='background:black;position:relative;left:'+xpos+';top:'+ypos+';'; 
    } 

    function getDimension(event,ui) 
    { 
     width=parseInt(ui.size.width); 
     height=parseInt(ui.size.height); 
     specs+='width:'+width+';height:'+height+';'; 
    } 

</script> 
</head> 
<body> 
<?php 
    $css="SELECT CSS FROM style"; 
    $css=mysql_query($css) or die(mysql_error()); 
    $css=mysql_fetch_array($css); 
    foreach($css as $c); 
?> 
<div id="prototype" style="<?echo $c?>"></div> 
<button onclick="JavaScript:sendIt(specs);">save</button> 
</body> 
</html> 

回答

0

你把它包裝的document.ready?你的jQuery不會處理加載時不存在的元素。

$(document).ready(function() { 
    ... 
}); 

或簡寫

$(function() { 
    ... 
}); 
+0

我加的是準備(),以每jQuery的功能,但它憑着工作要麼 – sammy 2013-03-19 15:43:00

+0

請更新你的新代碼的問題,並刪除所有的東西這是不相關的。 – isherwood 2013-03-19 15:44:05