当我使用时,此功能如何适用于所有文本框
$('#date, #date2').blur(function () {
但不是当我使用
$('#date').blur(function () {
?
MVC 查看器:
@Html.TextBoxFor(x => x.ArrivalDateStart, new { id = "date" })
@Html.TextBoxFor(x => x.ArrivalDateEnd, new { id = "date" })
@Html.TextBoxFor(x => x.OtherDateEnd, new { id = "date" })
@Html.TextBoxFor(x => x.OtherDateEnd, new { id = "date" })
Javascript:
$(function () {
$('#date, #date2').blur(function () {
var date = $(this).val();
var result = "";
if (date.length === 8) {
result = result += date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
$(this).val(result);
$(this).blur()
}
});
});