简体   繁体   English

如何禁用/取消选择由@ Html.EditorFor生成的元素(内部文本)或表内容

[英]How to disable/cancel selection of elements(text inside) generated by @Html.EditorFor or contents of table

How to cancel/disable selecting text: 如何取消/禁用选择文本:

  • generated by @Html.EditorFor @Html.EditorFor生成
  • or if not, just any text inside the web application 如果不是,则仅是Web应用程序内的任何文本
  • or if not, at least text in tables like this one below: 否则,至少要在下面的表格中输入文字:

By disabling selecting text I mean block possibility of marking/selectin/choosing text like on image below: 通过禁用选择文本,我的意思是阻止标记/选择/选择文本的可能性,如下图所示:

在此处输入图片说明

    <table class="table">
    <tr>
        <th>
            No.
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LastName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FirstName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.CellNumber)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.SecondaryPhoneNumber)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Address)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @noPerson @{noPerson++;}
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FirstName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CellNumber)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.SecondaryPhoneNumber)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Address)
            </td>
            <td>
                @Html.ActionLink("Details", "Details", new { id = item.Id }, new { @class = "btn btn-info btn-xs" }) |
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-warning btn-xs" })
                @if (Request.IsAuthenticated && User.IsInRole("Admin")) { <text> |</text>
                    @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { @class = "btn btn-danger btn-xs" })
                }
            </td>
        </tr>
    }
</table>

From other questions, just add CSS 从其他问题开始,只需添加CSS

body{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM