【问题标题】:Remove text onclick/onfocus event of @Html.TextArea删除 @Html.TextArea 的文本 onclick/onfocus 事件
【发布时间】:2013-05-30 08:46:00
【问题描述】:

我正在开发一个 MVC 3 项目。 在我看来,我有使用@Html.TextBox/TextArea 调用的文本框和文本区域。

谁能告诉我,我如何定义这些控件的 onclick 或 onfocus? 我找不到这方面的语法。

【问题讨论】:

  • 我正在使用 Razor 引擎进行查看。

标签: asp.net-mvc asp.net-mvc-3 onclick html.textbox


【解决方案1】:

文本框

@Html.TextBox("ControlName",
                "Some Value",
                  new { onclick = "alert('Razor Engine')" });
@Html.TextBoxFor(m => m.Value, new
                                {
                                    onclick = "alert('Razor Engine')",
                                    @Value = "Some Value"
                                });

文本区域

@Html.TextArea("ControlName",
                "Some Value",
                  new { onclick = "alert('Razor Engine')" });
@Html.TextAreaFor(m => m.Value, new
                                {
                                    onclick = "alert('Razor Engine')"
                                });

【讨论】:

    【解决方案2】:

    试试下面的方法。

     <%= Html.TextBox("obpt9",ViewData.Eval("obpt9"), new { onclick = "alert('hi')" })%>
    

    您可以从下面的链接中找到更多信息。 Add OnClick Event to Html.RadioButton

    【讨论】:

    • 用@代替
    猜你喜欢
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2014-09-22
    • 2017-08-27
    相关资源
    最近更新 更多