我不明白,如何在单击按钮时将文本设置为文本框。这是我的标记:
标记:
<div id="deploymentsGrid">
@if (db.CatalogCircumstances.Any())
{
@grid.GetHtml(
tableStyle: "table",
headerStyle: "table_HeaderStyle",
footerStyle: "table_PagerStyle",
rowStyle: "table_RowStyle",
alternatingRowStyle: "table_AlternatingRowStyle",
selectedRowStyle: "table_SelectedRowStyle",
columns: grid.Columns(
grid.Column("Nr", @Resources.Localization.nr, format: @<text>
@{ row = row + 1;} @item.Nr
</text>, style: "p13"),
grid.Column("Description", @Resources.Localization.description, format: @<text>
@{ row = row + 1;} @item.Description
</text>, style: "width:250px"),
grid.Column("", "", format: @<text>
<input id="select_bttn" style="width:78px" type="submit" [email protected] />
</text>)
)
)
}
<br />
</div>
<div class="container">
@using (Html.BeginForm("AddCircumstanceToList", "Health", FormMethod.Post))
{
@Html.HiddenFor(m => m.EmployeeId)
@Html.TextBoxFor(m => m.Nr, Model.Nr, new { style = "width:100px" })
@Html.TextBoxFor(m => m.Description, Model.Description, new { style = "width:450px" })
<br />
<br />
@Html.LabelFor(m => m.Start_date)
@Html.TextBoxFor(m => m.Start_date, new { id = "datepicker5" })
@Html.LabelFor(m => m.End_date)
@Html.TextBoxFor(m => m.End_date, new { id = "datepicker4" })
<br /><br />
<input type="submit" value="@Resources.Localization.save" style="width:78px" />
}
<button id="closer">@Resources.Localization.back</button>
</div>
而且我想在单击“ select-bttn”时将文本设置为文本框(在beginform内),然后单击“保存”按钮后发布到一个动作。
首先用以下代码替换您的代码select_bttn
:
<input id="select_bttn" class="select_bttn" style="width:78px" type="button" value="OK" data-nr="@item.Nr" data-description="@item.Description" />
其次,添加一个jQuery函数,该函数将获取所单击的行的Nr
和Description
属性,并设置两个文本框的值:
$(function () {
$(".select_bttn").click(function () {
var nr = $(this).data('nr');
var description = $(this).data('description');
var message = "You clicked on.Nr - " + nr + ".Description - " + description + ".";
alert(message);
$("#Nr").val(nr);
$("#Description").val(description);
});
});
输出:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句