javascript - 如何将 javascript 注入 HTMLhelper 文本字段
问题描述
我使用 asp.net mvc 创建了一个表单,我正在使用实体框架数据库。在表单上有文本字段,我如何在 html 帮助器中添加 javascript。
下面是文本字段
@Html.TextAreaFor(m => m.ShortSummary, htmlAttributes: new { onkeyup = UpdateLength(600, "ShortSummary", "count" ) })
<span id="count"></span>
下面是我创建的用于计算用户键入时的字符数的函数
<script type="text/javascript">
function UpdateLength(length, textID, spanID) {
var text = document.getElementById(textID);
var span = document.getElementById(spanID);
span.innerHTML = (length - text.value.length);
}
</script>
我想将上述功能添加到文本字段
解决方案
这段代码对我来说很好,感谢所有帮助
<textarea asp-for="ShortSummary" class = "form-control resizer" placeholder = "Short Summary (90 words)" tabindex = 1 rows = 8 onkeyup='UpdateLength(600, "ShortSummary", "count")'></textarea>
推荐阅读
- c# - 在 DataGrid 顶部添加自定义行 - WPF
- spring-boot - 将指标数据推送到 Prometheus
- ionic-framework - 离子和离子 CLI
- c++ - windows中ffmpeg的av_read_frame总是返回随机packet.stream_index
- java - 在本地微服务之间交换纯文本密码是一种好的编程习惯吗?
- asp.net-core - 部署到 IIS 时,String.Format 更改为 EU 格式
- java - 类未传递给 ClassFileTransformer
- class - 关于两个不同类实例的 AS3 hitTest 逻辑
- python - 如何在 vps 上使用 pyautogui?
- php - 在 laravel 应用程序中的所有错误/异常的维护视图页面下显示站点