想要用JAVASCRIPT实现文本框跟随鼠标的移动的效果
盼高手出现
------解决方案--------------------------------------------------------
是指拖拽效果吗? 去下yahoo的yui看一下吧...不想自己写js..也可以直接使用
------解决方案--------------------------------------------------------
你关键要搞清楚什么时候才停止跟随鼠标移动停止?
你的代码的问题是onmouseout估计没有执行到
------解决方案--------------------------------------------------------
将textbox设为绝对定位.
document.getElementById( "TextBox1 ").style.position= "absolute "
------解决方案--------------------------------------------------------
这样即可
<%@ Page Language= "C# " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
ICollection CreateDataSource( )
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn( "序号 ", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn( "学生姓名 ", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn( "语文 ", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn( "数学 ", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn( "英语 ", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn( "计算机 ", typeof(System.Decimal)));
for (int i = 0 ; i < 8 ; i++)
{
System.Random rd = new System.Random(Environment.TickCount * i); ;
dr = dt.NewRow();
dr[0] = i.ToString();
dr[1] = "【孟子E章】 " + i.ToString();
dr[2] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[3] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[4] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[5] = System.Math.Round(rd.NextDouble() * 100, 2);
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}
protected void Page_Load( object sender, EventArgs e )
{
if (!IsPostBack)
{
GridView1.DataSource = CreateDataSource();
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e )
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add( "onmouseover ", "showtext() ");
e.Row.Attributes.Add( "onmouseout ", "document.getElementById( ' " + TextBox1.ClientID + " ').value= ' ';document.getElementById( ' " + TextBox1.ClientID + " ').style.display= 'none ' ");
}
}
</script>
<script language= "Javascript ">
function showtext()
{
var t = document.getElementById( " <%=TextBox1.ClientID %> ")
t.style.display= "block "
x=document.body.scrollLeft+event.clientX; //获取当前鼠标位置的X坐标
y=document.body.scrollTop+event.clientY; //获取当前鼠标位置的Y坐标
t.style.left=x; //下面这两行有问题,不能实现移动
t.style.top=y;
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:GridView ID= "GridView1 " runat= "server " OnRowDataBound= "GridView1_RowDataBound ">