我有以下html代码,我想将其更改为使用html辅助方法。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
<label>Date of Birth</label>
<div class="input-group date" id="dtp">
<input name="Birthday" id="txtBirthday" class="form-control" onfocus="$(this).next().trigger('click')" onkeydown="event.preventDefault()" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
@Html.ValidationMessageFor(m => m.Birthday)
</div>
我想使用html帮助方法将上述html代码更改为以下内容,但我不知道如何在下面的代码中编写onkeydown="event.preventDefault()"
和$(this).next().trigger('click')"
。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
@Html.LabelFor(m => m.Birthday)
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday" })
@Html.ValidationMessageFor(m => m.Birthday)
</div>
答案 0 :(得分:1)
您可以将onfocus和onkeydown添加到添加@class = "form-control
的同一对象。如下所示
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday", onkeydown = "event.preventDefault()", onfocus = "$(this).next().trigger('click')" })