如何隐藏和显示 table 单元格文本?
How to hide and show a table cell text?
如何在单击密码列单元格时用 * 代替文本?再次点击后应该会显示密码。
<table class="table">
<tr>
<th><center>Name</center></th>
<th><center>Username</center></th>
<th ><center>Password</center></th>
<th><center>Mobile Number</center></th>
<th><center>Email</center></th>
<th colspan="2"><center>Actions</center></th>
</tr>
@foreach (var item in Model.Users)
{
<tr>
<td>@item.Name</td>
<td>@item.Username</td>
<td >@item.Password</td>
<td>@item.Mobile</td>
<td>@item.Email</td>
<td><a href="/admin/edit/@item.Id">Edit</a></td>
<td>@Html.ActionLink("Delete", "Delete",new {id=@item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</td>
</tr>
}
</table>
你可以这样做:
$('.table tr').each(function() {
var n = $("td:eq(2)", this);
var t = n.text();
n.html(`<div data-pass="${t}">******</div>`)
});
$('div[data-pass]').click(function() {
$(this).text($(this).text().indexOf('*') > -1 ? $(this).attr('data-pass') : '******')
})
演示
$('.table tr').each(function() {
var n = $("td:eq(2)", this);
var t = n.text();
n.html(`<div data-pass="${t}">******</div>`)
});
$('div[data-pass]').click(function() {
$(this).text($(this).text().indexOf('*') > -1 ? $(this).attr('data-pass') : '******')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table">
<thead>
<tr>
<th>
<center>Name</center>
</th>
<th>
<center>Username</center>
</th>
<th>
<center>Password</center>
</th>
<th>
<center>Mobile Number</center>
</th>
<th>
<center>Email</center>
</th>
<th colspan="2">
<center>Actions</center>
</th>
</tr>
</thead>
<tr>
<td>@item.Name</td>
<td>@item.Username</td>
<td>@item.Password</td>
<td>@item.Mobile</td>
<td>@item.Email</td>
<td><a href="/admin/edit/@item.Id">Edit</a></td>
<td>@Html.ActionLink("Delete", "Delete",new {id=@item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</td>
</tr>
</table>
如何在单击密码列单元格时用 * 代替文本?再次点击后应该会显示密码。
<table class="table">
<tr>
<th><center>Name</center></th>
<th><center>Username</center></th>
<th ><center>Password</center></th>
<th><center>Mobile Number</center></th>
<th><center>Email</center></th>
<th colspan="2"><center>Actions</center></th>
</tr>
@foreach (var item in Model.Users)
{
<tr>
<td>@item.Name</td>
<td>@item.Username</td>
<td >@item.Password</td>
<td>@item.Mobile</td>
<td>@item.Email</td>
<td><a href="/admin/edit/@item.Id">Edit</a></td>
<td>@Html.ActionLink("Delete", "Delete",new {id=@item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</td>
</tr>
}
</table>
你可以这样做:
$('.table tr').each(function() {
var n = $("td:eq(2)", this);
var t = n.text();
n.html(`<div data-pass="${t}">******</div>`)
});
$('div[data-pass]').click(function() {
$(this).text($(this).text().indexOf('*') > -1 ? $(this).attr('data-pass') : '******')
})
演示
$('.table tr').each(function() {
var n = $("td:eq(2)", this);
var t = n.text();
n.html(`<div data-pass="${t}">******</div>`)
});
$('div[data-pass]').click(function() {
$(this).text($(this).text().indexOf('*') > -1 ? $(this).attr('data-pass') : '******')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table">
<thead>
<tr>
<th>
<center>Name</center>
</th>
<th>
<center>Username</center>
</th>
<th>
<center>Password</center>
</th>
<th>
<center>Mobile Number</center>
</th>
<th>
<center>Email</center>
</th>
<th colspan="2">
<center>Actions</center>
</th>
</tr>
</thead>
<tr>
<td>@item.Name</td>
<td>@item.Username</td>
<td>@item.Password</td>
<td>@item.Mobile</td>
<td>@item.Email</td>
<td><a href="/admin/edit/@item.Id">Edit</a></td>
<td>@Html.ActionLink("Delete", "Delete",new {id=@item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</td>
</tr>
</table>