0

我正在尝试使用 jQuery 重新调整大小并拖动 div,获取新的位置和尺寸,然后发布到数据库。问题是,它不会重新调整大小,请帮助

这是代码...

<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>
4

1 回答 1

0

您是否将其包装在 document.ready 中?您的 jQuery 不会作用于加载时不存在的元素。

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

或速记

$(function() {
    ...
});
于 2013-03-18T17:27:29.713 回答