Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

html - How to hide and show a table cell text?

How can I put the * in place of text in the password column cells when clicked on it? After clicking again is should show the password.

    <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>
question from:https://stackoverflow.com/questions/66061140/how-to-hide-and-show-a-table-cell-text

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could do something like this:

$('.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') : '******')
})

demo

$('.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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...