我有一个页面,用户可以在单击按钮时使用 jquery 创建可调整大小和可拖动的动态文本框。
我想将文本框中的数据以及它们在页面上的高度宽度和位置从 javascript 传递到 php。
我对此感到有点困惑,任何帮助表示赞赏。
这是我的代码
<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<?
if($_SERVER['REQUEST_METHOD'] == "POST") {
$posted=$_POST['textarea'];
echo "posted=".$new_post."<br>";
}
?>
<head>
<style>
body{background-color:#ccc;}
.dragbox{position:absolute;top:20px;width:320px; height:0;padding: 0.0em; margin:25px; border:0;cursor:move; z-index:1;display: block; }
.textarea1{ width: 300px; height: 300px; padding: 0.5em;}
#handle{
display: block;
height: 16px;
width: 100px;
background-color: red;
position: relative;
top:10px;
font-size:10px;
}
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
<form id="frmMain" name="frmMain" enctype="multipart/form-data" action="dynamic_div.php" method="post">
<script>
var i=0;
var p=75;
function creatediv1(id) {
id=id+i;
var xp=xp+i;
var newdiv = document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.setAttribute('class', 'dragbox');
newdiv.setAttribute('contenteditable','true');
newdiv.style.position = "relative";
newdiv.style.top = p;
newdiv.style.cursor='move';
newdiv.innerHTML = "<div id='handle'>Drag me into position</div></div><br><textarea id="+i +" name='textarea["+i+"]' class='textarea1' width='300' style='overflow-y: auto;background-color:transparent;border: 2px dashed #000; '>some text here</textarea>";
document.body.appendChild(newdiv);
$(function() {
$( "#"+id ).draggable({
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var Stoppos = $(this).position();
$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top);
alert("left="+Stoppos.left+"top="+Stoppos.top);
}
});
$("#"+i).resizable({
stop: function(event, ui) {
var width = ui.size.width;
var height = ui.size.height;
alert("width="+width+"height="+height);
}
});
$("#"+i).draggable({handle:"#handle"});
});
i++;
p=p+25;
}
</script>
<input id="btn1" type="button" value="Add New textbox" onclick="creatediv1('draggable');" />
<input type="submit" value="Submit" >
</form>
</body>
</html>