"from"및 "to"필터의 2 입력에 대해 datepicker jquery로 작업하고 있습니다. 필터 (from/to) 중 하나가 선택되면 필요하게 만들고 싶습니다. 사용자가 날짜 필터를 사용하지 않으려는 경우 필요한 속성을 제거하고 싶습니다.datepicker가 첫 번째로드에서 작동하지 않습니다. jquery
그러나 "보낸 사람"입력에서 날짜를 선택하면 첫 번째 제출시 조치가 영향을받지 않습니다. 어떻게 "from"입력이 첫 번째로드에서 datepicker의 값을 인식하지 못했습니다.
누구나 왜 첫 번째 제출에서 작동하지 않을지 알 수 있습니까?
$(document).ready(function() {
if ($('#to').val().length == 0 && $('#from').val().length == 0) {
$('#from').removeAttr('required');
$('#to').removeAttr('required');
}
else if ($('#to').val().length > 0) {
$('#from').attr('required');
}
else if ($('#from').val().length > 0) {
$('#to').attr('required');
}
});
에서 입력
하고, 나는 그것이 기본적으로 필요한 설정하려면 : 여기
JQuery와 코드입니다.@Html.TextBoxFor(modelitem => Model.startdate, new { @class = "datepicker form-control" ,@placeholder = "Select From Date" , @id="from" , @required = "required" })
@Html.TextBoxFor(modelitem => Model.finishdate, new { @class = "datepicker form-control", @placeholder = "Select To Date" , @id = "to" , @required = "required" })
문제를 알려주세요.
당신의if else
문 내부
Alert("this is want to know on first run")
추가로 :
콘솔에서 오류가 발생하고 있습니까? 확인해 봤어? –
JsFiddle에서 이것을 재현 할 수 있습니까? – Marco