如何在内容页面的jQuery验证中引用html元素 [英] How to refer html element in jquery validation in content page
问题描述
runat =server
,我不知道如何在jquery验证中引用此id。 这是我的HTML代码:
< table>
< tr>
< td>
标题
< / td>
< td>
< select id =nameTitlerunat =serverclass =InputText>
< option value = - 1> - 选择 - < / option>
< option value =Mr。> Mr< / option>
< option value =Mrs。> Mrs< / option>
< option value =Miss。>小姐< / option>
< / select>
< / td>
< / tr>
< tr>
< td width =130px>
名字:< span class =RedMainText>< sup> *< / sup>< / span>
< / td>
< td>
< input type =textid =firstNameclass =InputTextsize =30/>
< / td>
< / tr>
< tr>
< td width =130px>
姓氏:< span class =RedMainText>< sup> *< / sup>< / span>
< / td>
< td>
< input type =textid =surnameclass =InputTextsize =30/>
< / td>
< / tr>
< / table>
jquery验证:
rules:
{
<%= nameTitle.UniqueID%>:{required:true},
firstName:{required:true},
姓:{required:true}
},
消息:
{
<%= nameTitle.UniqueID%>:{必填项:必填项},
姓:{必填项:必须填写姓氏},
姓:{必填项:姓氏为必填项}
}
这里 firstName
和 lastName
code> nameTitle 已经过验证。如何引用他们?请指教。 解决方案
在快速浏览 API Documentation 在我看来,假设 firstName
/ surname
项目链接到元素的名称
可以在将输入设置为如下之后尝试:
< input type =textid =firstNamename =firstNameclass =InputTextsize =30 />
< input type =textid =surnamename =surnameclass =InputTextsize =30/>
I have master and content page in asp .net web application. In my content page I am doing jquery validation. I have html element without runat="server"
and I don't know how to refer to this id in jquery validation.
Here is my HTML code:
<table>
<tr>
<td>
Title
</td>
<td>
<select id="nameTitle" runat="server" class="InputText">
<option value="-1">--Select--</option>
<option value="Mr.">Mr</option>
<option value="Mrs.">Mrs</option>
<option value="Miss.">Miss</option>
</select>
</td>
</tr>
<tr>
<td width="130px">
First Name:<span class="RedMainText"><sup>*</sup></span>
</td>
<td>
<input type="text" id="firstName" class="InputText" size="30" />
</td>
</tr>
<tr>
<td width="130px">
Surname:<span class="RedMainText"><sup>*</sup></span>
</td>
<td>
<input type="text" id="surname" class="InputText" size="30" />
</td>
</tr>
</table>
Jquery validation:
rules:
{
<%=nameTitle.UniqueID %>: { required: true },
firstName: { required: true },
surname: { required: true }
},
messages:
{
<%=nameTitle.UniqueID %>: { required: "Title is required" },
firstName: { required: "First Name is required" },
surname: { required: "Surname is required" }
}
Here firstName
and lastName
are not validated while nameTitle
is validated. How to refer them? please advise.
After taking a quick look at the API Documentation it appears to me that the firstName
/ surname
items are supposed to link to the Name
of an element
Could you please try it after setting the inputs up like so:
<input type="text" id="firstName" name="firstName" class="InputText" size="30" />
<input type="text" id="surname" name="surname" class="InputText" size="30" />
这篇关于如何在内容页面的jQuery验证中引用html元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!