JS获取坐标位置 . 方法传参 .
JS获取坐标位置 . 方法传参 . 救命啊。
function MyCollnection(TID,event) {
$.post("/CustomManager/MyStore?tid=" + TID, function (data) {
if (data.message == 1) {
window.location.href("../CustomManager/CustomManagerLogin");
}
else {
alert(data.message);
var e = event || window.event;
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
var x = e.pageX || e.clientX + scrollX;
var y = e.pageY || e.clientY + scrollY;
//alert('x: ' + x + '\ny: ' + y);
var oDiv = document.createElement('div');
oDiv.id = "Cdiv";
var oEvent = event;
oDiv.style.left = x + 'px';
oDiv.style.top = y + 'px'
alert(oDiv.style.left + ',' + oDiv.style.top);
oDiv.style.left = e.clientX + 'px'; // 指定创建的DIV在文档中距离左侧的位置
oDiv.style.top = e.clientY + 'px'; // 指定创建的DIV在文档中距离顶部的位置
alert(oDiv.style.left);
alert(oDiv.style.top);
oDiv.style.border = '4px solid silver'; // 设置边框
oDiv.style.position = 'absolute'; // 为新创建的DIV指定绝对定位
oDiv.style.width = '200px'; // 指定宽度
oDiv.style.height = '50px'; // 指定高度
oDiv.innerHTML = "<div id=\"statusbar\"><ul style=\"background-color:silver;float:right;width:100%\"><button onclick=\"hidePopup();\">关闭<button></ul><ul><li><strong>页面收藏成功 将于3秒后关闭;</strong></li></ul></div>";
document.body.appendChild(oDiv);
}
});
}
需要在上面这个方法里获取位置,TID参数是必要的。该怎么写 。 如果只写一个event倒是能得到位置,两个参数就不行了。求教 .
------解决方案--------------------
不明白,你这样调用不就行了
$("#aaa").mousedown(function(event){
MyCollnection("123",event);
})
------解决方案--------------------
你的event是怎么传进function (data) 的?function (data, event) 试一下
------解决方案--------------------
dom.onclick=function(e){MyCollnection("id",e);};
function MyCollnection(TID,event) {
$.post("/CustomManager/MyStore?tid=" + TID, function (data) {
if (data.message == 1) {
window.location.href("../CustomManager/CustomManagerLogin");
}
else {
alert(data.message);
var e = event || window.event;
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
var x = e.pageX || e.clientX + scrollX;
var y = e.pageY || e.clientY + scrollY;
//alert('x: ' + x + '\ny: ' + y);
var oDiv = document.createElement('div');
oDiv.id = "Cdiv";
var oEvent = event;
oDiv.style.left = x + 'px';
oDiv.style.top = y + 'px'
alert(oDiv.style.left + ',' + oDiv.style.top);
oDiv.style.left = e.clientX + 'px'; // 指定创建的DIV在文档中距离左侧的位置
oDiv.style.top = e.clientY + 'px'; // 指定创建的DIV在文档中距离顶部的位置
alert(oDiv.style.left);
alert(oDiv.style.top);
oDiv.style.border = '4px solid silver'; // 设置边框
oDiv.style.position = 'absolute'; // 为新创建的DIV指定绝对定位
oDiv.style.width = '200px'; // 指定宽度
oDiv.style.height = '50px'; // 指定高度
oDiv.innerHTML = "<div id=\"statusbar\"><ul style=\"background-color:silver;float:right;width:100%\"><button onclick=\"hidePopup();\">关闭<button></ul><ul><li><strong>页面收藏成功 将于3秒后关闭;</strong></li></ul></div>";
document.body.appendChild(oDiv);
}
});
}
需要在上面这个方法里获取位置,TID参数是必要的。该怎么写 。 如果只写一个event倒是能得到位置,两个参数就不行了。求教 .
------解决方案--------------------
不明白,你这样调用不就行了
$("#aaa").mousedown(function(event){
MyCollnection("123",event);
})
------解决方案--------------------
你的event是怎么传进function (data) 的?function (data, event) 试一下
------解决方案--------------------
dom.onclick=function(e){MyCollnection("id",e);};