我requiredfieldvalidator
对一些文本框使用 a ,每个文本框都有占位符属性,但是当我单击提交按钮时,验证器没有触发,这个问题在 IE 中,因为 IE 默认不支持占位符,所以我为此目的使用 Jquery,这是我的代码:
查询:
<script type="text/javascript">
$(document).ready(function () {
// $("#txtAddress").removeAttr("style");
var userAgent = navigator.userAgent.toString().toLowerCase();
if (userAgent.indexOf('ie') != -1) {
$('[placeholder]').focus(function () {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function () {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
}
});
</script>
ASP:
<asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
<p>
<asp:TextBox ID="txtOrgName" runat="server" placeholder="ناوی دامەزراوە"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ForeColor="red" CssClass="validator" ControlToValidate="txtOrgName" ErrorMessage="*"></asp:RequiredFieldValidator>
</p>
<br/>
<p>
<asp:TextBox ID="txtPhone" runat="server" placeholder="تەلەفۆن"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="validator" ControlToValidate="txtPhone" ForeColor="red" ErrorMessage="*"></asp:RequiredFieldValidator>
</p>
<br/>
<p>
<asp:TextBox ID="txtMobile" runat="server" placeholder="مۆبایل"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtMobile" CssClass="validator" ForeColor="red" ErrorMessage="*"></asp:RequiredFieldValidator>
</p>
<br/>
<p>
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Height="120px" Width="200px" style="direction: ltr;" placeholder="ناونیشان">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtAddress" CssClass="validator" ForeColor="red" ErrorMessage="*"></asp:RequiredFieldValidator>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="تۆمارکردن" />
</p>