我正在尝试使用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>
答案 0 :(得分:0)
你把它包装在document.ready中了吗?你的jQuery不会对加载时不存在的元素起作用。
$(document).ready(function() {
...
});
或简写
$(function() {
...
});