Próbuję dodać warunki do zmiennej, a następnie przypisać w warunku if(), ale nie działa zgodnie z oczekiwaniami.jQuery Wiele warunków w jednej zmiennej
Wypróbowane możliwości:
1)
conditionCheck = (getMonth == undefined || getMonth == "" || getMonth == null
|| getDay == undefined || getDay == "" || getDay == null
|| getYear == undefined || getYear == "" || getYear == null)
2)
conditionCheck = getMonth == undefined || getMonth == "" || getMonth == null
|| getDay == undefined || getDay == "" || getDay == null
|| getYear == undefined || getYear == "" || getYear == null
3)
conditionCheck = "getMonth == undefined || getMonth == "" || getMonth == null
|| getDay == undefined || getDay == "" || getDay == null
|| getYear == undefined || getYear == "" || getYear == null"
ale jeśli dodać jak jest w stanie następnie jego pracy w porządku.
lubię to. ->
if (getMonth == undefined || getMonth == "" || getMonth == null
|| getDay == undefined || getDay == "" || getDay == null
|| getYear == undefined || getYear == "" || getYear == null) {
} else {
ageCalculation();
}
Każdy pomysł/sugestia?
Zmieniano:
function ageCalculation() {
getDate = getYear + "-" + getMonth + "-" + getDay;
dob = new Date(getDate);
today = new Date();
age = (today - dob)/(365.25 * 24 * 60 * 60 * 1000);
if (age < 3 || age == 3 || age > 3 && age < 3.00452422294471007) {
$('.greater-msg, .less-then-msg').remove();
$(contentParent).find('.fieldset-wrapper').after('<div class="less-then-msg">Disclaimer: In compliance with EO51, cannot directly engage with mothers with children aged 0 to 3 years old. All content that you will receive via email will only be regarding your pregnancy. </div>');
} else if (age > 3) {
$('.greater-msg, .less-then-msg').remove();
$(contentParent).find('.fieldset-wrapper').after('<div class="greater-msg">You can also visit to know how you can keep giving your child the 360 advantage.</div>');
}
if (age <= -1 || age <= -0 || age == 0 || age == -0) {
$('.greater-msg, .less-then-msg').remove();
}
}
Dzięki !!
Co masz na myśli, mówiąc, że nie działa. co zrobiłeś ze zmienną conditionCheck –
nie masz ciała dla swojego 'if '. Również trzecia to tylko ciąg, który oceni "prawda". –
to dobrze, aby dodać ciąg znaków zmienna lub liczba zgodnie z typem danych. Zmienne nie są dla Sprawdź warunki .. chociaż jeśli chcesz dodać let przed zmiennymi – mayur