Skip to main content
 首页 » 编程设计

c#之鼠标悬停时显示说明

2024年02月05日10haluo1

我需要将鼠标悬停在表格中name属性上面时,显示表格中描述栏的内容。这是模型类。

我有一个表,其中包含列名称、类型和描述。我需要在索引 View 中使用列描述作为我的悬停文本。

public class mouseover 
{ 
    public int ID { get; set; } 
    public string name { get; set; } 
    public string type { get; set; } 
    public string description { get; set; } 
} 

查看

@model IEnumerable<description.Models.mouseover> 
 
@{ 
ViewBag.Title = "Index"; 
} 
<h2>Index</h2> 
<p> 
@Html.ActionLink("Create New", "Create") 
</p> 
<table class="table"> 
<tr> 
    <th> 
        @Html.DisplayNameFor(model => model.name) 
    </th> 
    <th> 
        @Html.DisplayNameFor(model => model.type) 
    </th> 
    @*<th> 
        @Html.DisplayNameFor(model => model.description) 
    </th>*@ 
    <th></th> 
</tr> 
 
@foreach (var item in Model) { 
<tr> 
    <td> 
        @Html.DisplayFor(modelItem => item.name) 
    </td> 
    <td> 
        @Html.DisplayFor(modelItem => item.type) 
    </td> 
    @*<td> 
        @Html.DisplayFor(modelItem => item.description) 
    </td>*@ 
    <td> 
        @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | 
        @Html.ActionLink("Details", "Details", new { id=item.ID }) | 
        @Html.ActionLink("Delete", "Delete", new { id=item.ID }) 
    </td> 
</tr> 
} 

请您参考如下方法:

您可以使用 HTML title 全局属性,但为什么不使用 Boostrap 工具提示来实现您的目标呢?

Documentation

检查这个Fiddle : 它有一个简单的表格,只有一行和一列,例如您的表格。

<td data-toggle="tooltip" title="Description" data-placement="right"> 
    Name 
</td> 

如您所见,您只需使用 @item.name 和 @item.description 更改名称和描述。 您还必须启用工具提示:

$(function () { 
  $('[data-toggle="tooltip"]').tooltip(); 
}) 

请记住包含所有需要的 css 和 js 文件,当然还有 jQuery 和 Bootstrap:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 

让我知道这是否有用。