如果你在asp.net工作,你可以使用你的不同的控制RequiredFieldValidator
如下面的例子:
<tr>
<td>
<asp:RequiredFieldValidator runat=server
ControlToValidate=txtName
ErrorMessage="Identifier is required."> *
</asp:RequiredFieldValidator>
</td>
<td>User Identifier :</td>
<td><input type=text runat=server id=txtName></td>
</tr>
爲必填字段,然後使用類似jQuery的獲取數據您可以使用ValidationSummary
屬性,在必填字段前面顯示「*」。
<asp:ValidationSummary runat=server
headerText="there is error on this page/>
,不要忘記驗證方法:
public sub OnSubmit(source as Object, e as EventArgs)
if Page.IsValid then
' Some code
end if
end sub
請包括嘗試的解決方案,爲什麼他們沒有工作,和預期的結果。 –
如果你想要自定義屬性,那麼[使用他們的標準](http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data- * -attributes),如果你想標記一個表單控件爲強制的,不要發明你自己的屬性,使用[標準的](http://www.w3.org/TR/html5/forms.html# ATTR-textarea的要求的) – Quentin