【发布时间】:2019-04-29 03:48:51
【问题描述】:
我在验证 for 循环中的每个 PhoneNumber 文本框时遇到问题。 我的验证功能适用于单个 Texbox,但是当我尝试应用于循环时,我不知道 javascript 如何理解循环的索引。
需要帮助!
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
<div>
<b>Phone Number:</b>
@Html.EditorFor(model => model[i].Hotline, new { htmlAttributes = new { @class = "form-control ShortInput", id = "hotline[i]//html doesn't understand the index here" maxlength = "15" } })
<span class="ErrorBlock field-validation-valid"></span>
</div>
</td>
</tr>
这是验证函数:
function validateForm() {
var result = true;
result = checkPhone('#hotLine//"how could I get the index here"', 'Invalid phone number.') && result;
return result;
}
【问题讨论】:
-
嗯,你要做的是首先获取所有元素,你可以通过使用 css 类并在 jquery 中从类名中搜索元素来获取这些元素,在你获取所有元素之后,你可以使用 foreach 获取所有元素一一验证
标签: javascript c# html