在EditorFor

时间:2016-06-16 18:19:02

标签: javascript jquery asp.net-mvc razor editorfor

我想知道是否有任何方法可以触发“点击”。当我按下(或周围)glyphicon图标时,编辑器的事件?

以下是代码:

<div class="col-md-10">
@Html.EditorFor(model => model.FullName, new { htmlAttributes = new { @class = "form-control" } })
<span style="font-size:1.5em;" id="f1" class="glyphicon glyphicon-question-sign  form-control-feedback"></span>
 @Html.ValidationMessageFor(model => model.FullName, "", new { @class = "text-danger" })

</div>

由于

1 个答案:

答案 0 :(得分:1)

首先给编辑器提供一个id:

    @Html.EditorFor(model => model.FullName, new { htmlAttributes = new { @class = "form-control", @id = "e1" } })
    <span style="font-size:1.5em;" id="f1" class="glyphicon glyphicon-question-sign  form-control-feedback"></span>

然后使用jQuery如下:

$("#f1").bind("click", (function () {
    $("#e1").trigger("click");  
}));