当我拖动一个DIV时,如何传递一个id的值给一个函数
How to pass value of a id to a function when I drag a DIV?
这是我的Javascript
$(document).ready(function(){
$( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6,
stop : function () {
var x = $(this).position().left;
var y = $(this).position().top;
$.ajax({
url: "savedrag.php", /* You need to enter the URL of your server side script*/
type: "POST",
/* add the other variables here or serialize the entire form.
Image data must be URI encoded */
data:{
x: x,
y: y
},
success: function(msg)
{
alert("position save");
}
})
}
});
});
是我的PHP
<?php
$qry = "SELECT * from contact Where CustomerID='$pid'";
$result = mysql_query($qry);
while ($row = mysql_fetch_array($result))
{
echo '<div class="ex">';
$row["ContactID"];
echo '</div>';
}
?>
如何将变量$row["ContactID"]传递到每个函数中,以便每个可拖动的div在数据库中有自己的单独位置?
之前我通过onclick(this)传递值;但是我不能为draggable做同样的事情
使用给定的标记,您可以
$(document).ready(function() {
$(".ex").draggable({
containment : 'parent',
cursor : 'pointer',
opacity : 0.6,
stop : function() {
var x = $(this).position().left;
var y = $(this).position().top;
$.ajax({
url : "savedrag.php",
type : "POST",
data : {
x : x,
y : y,
ContactID: $.trim($(this).html())
},
success : function(msg) {
alert("position save");
}
})
}
});
});
你的意思是:
Javascript添加:
var id = $(this).attr("id");
//...
data:{
x: x,
y: y,
id: id
}
php: echo '<div class="ex" id="$row["ContactID"];">';
echo '</div>';
相关文章:
- 向更新mysql查询传递一个id
- Javascript:表单验证getElementById仅返回第一个id元素
- JS在隐藏未定义的值后仅从数组中返回第一个id的值
- Meteor:访问另一个集合,每个块中有一个id
- js组合对象只返回一个id
- 给每个谷歌距离矩阵结果一个id
- 如何附加一个id's的详细信息只通过php或jquery提供一次
- Ember eror试图注册一个id已在使用的视图
- 如何使用innerHTML更改图像大小来给它一个id Javascript
- 具有一个#id的多选选项可显示n个隐藏表
- 设置一个按钮按下函数来触发一个Id为的Ajax调用
- 如何创建一个每行列数未知的html表,对齐列,并为每个单元格/行指定一个id
- jQuery鼠标滚动到下一个id
- 如何在 JavaScript 中获取另一个 ID 下的 ID
- Javascript 保存相同的 ID,而不会在 LocalStorage 中覆盖另一个 ID
- 如何在 html 中调用另一个 ID 中的特定 ID
- 将事件绑定到类中的所有元素,而不仅仅是一个 id
- 使用 JSP 为
-Elements 提供一个 ID - JS只使用一个id,忽略另一个id
- 找到一个按钮并通过jQuery / JavaScript分配一个ID