按住左键 在table上拖选一块区域 拖选完后,想获得 td的id 如上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 拖选,捕获当鼠标左键按下时,鼠标的移动伪代码如下:var leftHasDown = false;document.onmousedown = function (){ if(左键){ leftHasDown = true; }};document.onmousemove = function (){ if(leftHasDown){ event.toElement.id;//当前鼠标移动到的TD的ID }}; 网上找了个拖动的,帮你改了改,不知道是不是你要的效果 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>可以用鼠标拖动的表格</title> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- var currentMoveObj = null; //当前拖动对象 var relLeft; //鼠标按下位置相对对象位置 var relTop; function f_mdown(obj) { currentMoveObj = obj; //当对象被按下时,记录该对象 currentMoveObj.style.position = "absolute"; relLeft = event.x - currentMoveObj.style.pixelLeft; relTop = event.y - currentMoveObj.style.pixelTop; } window.document.onmouseup = function() { currentMoveObj = null; //当鼠标释放时同时释放拖动对象 } function f_move(obj) { //获取id if(currentMoveObj != null) { document.getElementById('div').innerHTML = '你要的id是:'+currentMoveObj.id; currentMoveObj.style.pixelLeft=event.x-relLeft; currentMoveObj.style.pixelTop=event.y-relTop; } } //--> </SCRIPT> <BODY> <TABLE width="100" border=1 onselectstart="return false" > <TR> <TD align="center" id="test1" style="position:absolute;left:50;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">test1</TD> <TD align="center" id="test2" style="position:absolute;left:100;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">test2</TD> </TR> </TABLE> <div id="div" style="position:absolute;left:50;top:300"></div> </body> </html> 大哥,我要的是拖选拖选拖选拖选鼠标按下,拖选一个区域块,释放鼠标,获得区域块中table td 的id 这效果只有在google的doc见过,LZ可以去看看google是怎么实现的 jQuery UI,有提供类似功能的插件:http://jqueryui.com/demos/selectable/#display-grid 这个链接演示了如何获取选择到的元素ID。http://jqueryui.com/demos/selectable/#serialize 以前看过这两个jQuery UI的demo,但从没注意过有这功能,呵呵,很好 JS得到一个网页的HTML代码 jquery新手问题4 有谁知道dojo 1.3.1版本和1.1.1版本的区别是什么 帮忙看这背景色怎么写呀,有点难的喽。。在线等。。。 jS如何弹出3个选择的对话框? JavaScript用正则表达式怎样验证只能为数字 急啊,<select>option的问题希望能帮我分析一下 function的调用问题? onclick怎么调用text的value? 正则的问题, 帮个忙 梅花雪(tree)单选框选不中的问题,请高手赐教,分不多,拜谢! js 关于存取xml相同节点的问题
var leftHasDown = false;
document.onmousedown = function (){
if(左键){
leftHasDown = true;
}
};document.onmousemove = function (){
if(leftHasDown){
event.toElement.id;//当前鼠标移动到的TD的ID
}
};
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>可以用鼠标拖动的表格</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
var currentMoveObj = null; //当前拖动对象
var relLeft; //鼠标按下位置相对对象位置
var relTop;
function f_mdown(obj)
{
currentMoveObj = obj; //当对象被按下时,记录该对象
currentMoveObj.style.position = "absolute";
relLeft = event.x - currentMoveObj.style.pixelLeft;
relTop = event.y - currentMoveObj.style.pixelTop;
}
window.document.onmouseup = function()
{
currentMoveObj = null; //当鼠标释放时同时释放拖动对象
}
function f_move(obj)
{
//获取id
if(currentMoveObj != null)
{
document.getElementById('div').innerHTML = '你要的id是:'+currentMoveObj.id;
currentMoveObj.style.pixelLeft=event.x-relLeft;
currentMoveObj.style.pixelTop=event.y-relTop;
}
}
//-->
</SCRIPT>
<BODY>
<TABLE width="100" border=1 onselectstart="return false" >
<TR>
<TD align="center" id="test1" style="position:absolute;left:50;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">test1</TD>
<TD align="center" id="test2" style="position:absolute;left:100;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">test2</TD>
</TR>
</TABLE> <div id="div" style="position:absolute;left:50;top:300"></div>
</body>
</html>
鼠标按下,拖选一个区域块,释放鼠标,获得区域块中table td 的id
http://jqueryui.com/demos/selectable/#display-grid
http://jqueryui.com/demos/selectable/#serialize