我正在尝试使用onkeyup事件从表的列中调用一个函数calculfac()来处理每个更改。该列是数字列,如果我们在该列中键入任何值,则该列的所有数字应存储在变量中。但是当我在NetHrs列中输入值时,函数不会被调用--这里是代码
<tbody>
<tr>
<td>@Html.EditorFor(model => model.FromDate, new { htmlAttributes = new { @class = "form-control datepicker w-100" } })</td>
<td>@Html.EditorFor(model => model.ToDate, new { htmlAttributes = new { @class = "form-control datepicker w-100" } })</td>
<td>@Html.EditorFor(model => model.NetHrs, new { onkeyup = "calculfac()", htmlAttributes = new { type = "number", @class = "form-control w-100 empHrs" } })</td>
<td>@Html.EditorFor(model => model.HolidayEnt, new { htmlAttributes = new { @class = "form-control w-100", @readonly = "readonly" } })</td>
<td><a href="" title="Delete Rows">Delete</a></td>
</tr>
</tbody>
<script>
function calculfac() {
var nethrs = // Here the value from that column should be stored including typed value
}
</script>
发布于 2021-08-21 02:17:41
试图使用onkeyup事件从表的列中调用每个更改的函数calculfac()。该列是数字列,如果我们在该列中键入任何值,则该列的所有数字应存储在变量中。
要实现您的需求,您可以参考以下代码示例。
<td>@Html.EditorFor(model => model.NetHrs, new { htmlAttributes = new { type = "number", @class = "form-control w-100 empHrs", @onkeyup = "calculfac(this)" } })</td>或通过onchange事件触发该函数。
<td>@Html.EditorFor(model => model.NetHrs, new { htmlAttributes = new { type = "number", @class = "form-control w-100 empHrs", @onchange = "calculfac(this)" } })</td>JS码
function calculfac(el) {
var nethrs = $(el).val();
console.log("new value is ", nethrs);
//...
//your code logic here
//...
}https://stackoverflow.com/questions/68860782
复制相似问题