javascript - 单击时如何将 Html.PasswordFor 更改为 Html.TextboxFor?
问题描述
当我单击Javascript 或 jQuery 时单击span
要更改的标记Html.PasswordFor()
时。Html.TextboxFor()
我怎样才能做到这一点?我在输入字段中知道这一点,但在 Html Helpers 中我不知道。
@Html.PasswordFor(x => x.Parola, new
{
placeholder = "Password *",
@class = "form-control p-4 font-weight-bold mb-4",
style = "position:relative;",
required = "required"
})
<span style="position:absolute;right:20px;top:192px;">
<i class="fas fa-eye fa-1x"></i>
</span>
解决方案
当我单击Javascript 或 jQuery 时单击我想要更改的跨度标记
Html.PasswordFor()
时。Html.TextboxFor()
我怎样才能做到这一点?
正如评论中提到的@charlietfl 和@freedomn-m,诸如此类的Html.PasswordFor()
HTMLHtml.TextboxFor()
助手(或其他标签助手)使Web 开发人员能够在服务器端以C# 代码创建和呈现HTML 元素。JavaScript 或 jQuery 代码在浏览器客户端执行,因此您不能在 JS 客户端直接更改这些服务器端 HTML Helpers 代码。
此外,如果您想从客户端将密码输入动态切换为常规文本输入,您可以尝试:
html代码片段
<span id="btnpwdmode" style="position:absolute;right:20px;top:192px;">
<i class="fa fa-eye fa-1x"></i>
</span>
jQuery 代码片段
$("#btnpwdmode").click(function () {
var pwd_input_mode = $("#ID").attr("type");
if (pwd_input_mode == "password") {
$("#ID").attr("type", "text");
} else {
$("#ID").attr("type", "password");
}
})
有关 HTML Helpers 和 Tag Helpers 的更多信息,您可以查看此文档:
推荐阅读
- c# - C# - 使用 CSVContext Read() 和 Count() 从 CSV 读取已删除行的问题
- python - setup.py 如何安装包
- angular - Ionic4:将图像大小作为背景图像 url 的封面
- javascript - 在传递字符串 trim() 的 Vue.JS 方法中不起作用
- java - 列出 HADOOP 2.x 中映射器和缩减器数量的命令
- node.js - 将 mongodb 对象 ID 设置为“String”而不是“Schema.Types.ObjectId”是不好的做法吗?
- php - 为什么 $_GET 没有从不同的页面获取数据?
- java - 如何提取包含已字符串化为 Java 类的 ISO8385 字段以及匹配字段的 JSON 内容?
- python - 安装 2.7.5 时的段错误
- c++ - 从方法返回 JsonDoc 作为引用