我在VB.Net代码隐藏中动态创建文本框。
我想使用JQuery检查并查看该特定文本字段的值是否为" min"或" max",然后清除值。我的代码隐藏代码是:
Dim txtStartYear As New TextBox
Dim txtEndYear = New TextBox
txtStartYear.ID = "txt" & id.Name & "_start"
txtEndYear.ID = "txt" & id.Name & "_end"
txtEndYear.Width = 50
txtStartYear.Width = 50
txtStartYear.Text = "min"
txtEndYear.Text = "max"
txtStartYear.CssClass = "YearValue"
txtEndYear.CssClass = "YearValue"
HTML code:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function () {
$(".DateField").datepicker();
});
$(".YearValue").each(function (item, index) {
//Check if value is min or max
if ($(this).val() == "min" || $(this).val() == "max") {
alert("Wrong value entered.");
}
});
</script>
我使用CSS类来区分文本框。如何使用jQuery检查文本框(cssclass="YearValue"
)是否包含&#34; min
&#34;或&#34; max
&#34; (如果是,那么清空字段)?
答案 0 :(得分:2)
这样的东西?
$(function(){
$(".YearValue").click(function(){
if ($(this).val() == "min" || $(this).val() == "max") {
alert("Wrong value entered.");
}
});
});
查看此fiddle