zoukankan      html  css  js  c++  java
  • Gridview中鼠标移动到项中的小图片后把图片放大

    前端代码:

    JS代码
    1 function Test(aa)
    2 {
    3 document.getElementById("img1").src ="Image/"+aa;
    4 document.getElementById("div1").style.display='block';
    5 document.getElementById("div1").style.position='absolute';
    6 var x = event.clientX;
    7 var y = event.clientY;
    8 document.getElementById("div1").style.left = x;
    9 document.getElementById("div1").style.top = y;
    10 }
    11 function Hide()
    12 {
    13 document.getElementById("div1").style.display='none';
    14 }
    页面源码
    1 <div id ="div1" style="display:none;">
    2 <img src ='' id="img1" width="150px" height="150px"/>
    3 </div>
    4 <div>
    5 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    6 <Columns>
    7 <asp:TemplateField HeaderText="头像">
    8 <ItemTemplate>
    9 <img src='Image/<%#Eval("ImagePath") %>' onmouseout="Hide()" onmouseover="Test('<%#Eval("ImagePath") %>')" width="70px" height="80px" />
    10 </ItemTemplate>
    11 </asp:TemplateField>
    12 <asp:BoundField DataField="UserName" HeaderText="用户名" />
    13 <asp:BoundField DataField="Age" HeaderText="年龄" />
    14 <asp:BoundField DataField="Email" HeaderText="邮箱" />
    15 <asp:BoundField DataField="Address" HeaderText="地址" />
    16 </Columns>
    17 </asp:GridView>

    后台代码:

    后台代码
    1 protected void Page_Load(object sender, EventArgs e)
    2 {
    3 if (!IsPostBack)
    4 {
    5 databind();
    6 }
    7 }
    8 public void databind()
    9 {
    10 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ToString());
    11 SqlCommand cmd = new SqlCommand();
    12 cmd.Connection = con;
    13 cmd.CommandText = "Select * From T_Users";
    14 SqlDataAdapter da = new SqlDataAdapter(cmd);
    15 DataSet ds = new DataSet();
    16 da.Fill(ds);
    17 this.GridView1.DataSource = ds.Tables[0];
    18 this.GridView1.DataKeyNames = new string[] { "id" };
    19 this.GridView1.DataBind();
    20 }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    yii2中的url美化
    一级域名301重定向到www二级域名
    使用meta来控制浏览器的渲染方式
    同一页面不同编码的提交处理
    Yii2.0 UrlManager
    sqlsever连接两个不同服务器上的数据库进行查询
    php 实现传入参数的传出
    xcode如何修改项目名称
    ios如何实现应用之间的跳转
    ios程序如何实现系统自带的分享
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1964937.html
Copyright © 2011-2022 走看看