javascript - ASP.NET - 可以在按钮上创建带有 onclick 事件的标签吗?
问题描述
我有一个带有 TextArea 的页面,可让您发送一条消息。但就我而言,我想发送几条消息。
我想有一个按钮,可以根据需要创建一个新的 TextArea,但我没有找到解决方案。
@Html.TextAreaFor(m => m.MessageToSend, new { style = "width: 1200px; height: 600px;" })
上面是我想通过单击按钮创建/复制的文本框。
-- 我已经可以发送消息了,我只想通过单击按钮创建其他 TextArea
解决方案
是的,你可以,首先你需要安装 jquery。然后,您需要将代码放在 div 中,例如:
<div id="multiple">
@Html.TextAreaFor(m => m.MessageToSend, new { style = "width: 1200px; height: 600px;"
})
</div
然后创建一个按钮来添加多个办公桌,例如:-
<button class="btn btn-primary" onclick="adder()">Adder</button>
在,最后写脚本
<script>
function adder()//This function is called when u click that button
{
var html='';
html += '@Html.TextAreaFor(m => m.MessageToSend, new { style = "width: 1200px; height: 600px;" })
})';
$("#multiple").append(html); //This will stack your html input inside that id as we have name multiple and given id
}
</script>
但是,您需要管理您的控制器
推荐阅读
- php - PHP [process_control_timeout] 冻结应用程序
- node.js - Node.js 项目中的中间件/错误
- c# - 如何在不使用 c# 形式的计时器的情况下使用性能计数器?我收到一个错误,例如找不到类别名称
- java - 无法从 Java 中找到到所请求目标的有效认证路径,但可以通过浏览器登录
- go - 如何为 Go 包装器正确配置 ffmpeg
- linker-errors - C 中未定义的引用和链接器错误
- angular - $any() 类型转换成角度的用途和目的是什么
- javascript - 如何以角度显示每小时前的数据
- python - 从数据框的单元格中删除特定值并将值向左移动
- java - 使用 ActiveDirectoryLdapAuthenticationProvider 和嵌入式 ldif 的 Spring 身份验证