В котором я нуждаюсь в помощи, это во время показывания выборов времени, только выполняют 2 primeran условия IF
<!DOCTYPE html>
<html>
<body>
<!--Esto hace que se cree una lista con los horarios-->
<select name="custom_type" id="time" onfocusin="timeSlot()" class="elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save" data-type="extra"
type="custom_type" data-custom-type="Webinar Time">
<option value="0">Select Your Time</option>
<option value="1">12:00 AM</option>
<option value="2">12:30 AM</option>
<option value="3">1:00 AM</option>
<option value="4">1:30 AM</option>
<option value="5">2:00 AM</option>
<option value="6">2:30 AM</option>
<option value="7">3:00 AM</option>
<option value="8">3:30 AM</option>
<option value="9">4:00 AM</option>
<option value="10">4:30 AM</option>
<option value="11">5:00 AM</option>
<option value="12">5:30 AM</option>
<option value="13">6:00 AM</option>
<option value="14">6:30 AM</option>
<option value="15">7:00 AM</option>
<option value="16">7:30 AM</option>
<option value="17">8:00 AM</option>
<option value="18">8:30 AM</option>
<option value="19">9:00 AM</option>
<option value="20">9:30 AM</option>
<option value="21">10:00 AM</option>
<option value="22">10:30 AM</option>
<option value="23">11:00 AM</option>
<option value="24">11:30 AM</option>
<option value="25">12:00 PM</option>
</select>
<div class="form-group">
<script type="text/javascript">
//todo este codigo esconde las opciones
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[0].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[1].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[2].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[3].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[4].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[5].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[6].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[7].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[8].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[9].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[10].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[11].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[12].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[13].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[14].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[15].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[16].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[17].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[18].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[19].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[20].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[21].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[22].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[23].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[24].style.display = 'none';
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[25].style.display = 'none';
//esto se supone que muestra la opcion correspondiente a la hora del dia (aqui //es donde nececito ayuda)
// ignoren esto(jdshfojhsdfohsdofjhsdofhsdofhoñsdjfhoñsdjfhñosjdhhhhfhfhfhfjfhdfhj bndjnvj bn)
function timeSlot() {
var hour = new Date().getHours();
var minutes = new Date().getMinutes();
if (hour = 0, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[2].style.display = 'block';
} else if (hour = 0, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[3].style.display = 'block';
} else if (hour = 1, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[4].style.display = 'block';
} else if (hour = 1 && minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[5].style.display = 'block';
} else if (hour = 2, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[6].style.display = 'block';
} else if (hour = 2 && minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[7].style.display = 'block';
} else if (hour = 3, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[8].style.display = 'block';
} else if (hour = 3, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[9].style.display = 'block';
} else if (hour = 4, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[10].style.display = 'block';
} else if (hour = 4, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[11].style.display = 'block';
} else if (hour = 5, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[12].style.display = 'block';
} else if (hour = 5, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[13].style.display = 'block';
} else if (hour = 6, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[14].style.display = 'block';
} else if (hour = 6, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[15].style.display = 'block';
} else if (hour = 7, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[16].style.display = 'block';
} else if (hour = 7, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[17].style.display = 'block';
} else if (hour = 8, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[18].style.display = 'block';
} else if (hour = 8, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[19].style.display = 'block';
} else if (hour = 9, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[20].style.display = 'block';
} else if (hour = 9, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[21].style.display = 'block';
} else if (hour = 10, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[22].style.display = 'block';
} else if (hour = 10, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[23].style.display = 'block';
} else if (hour = 11, minutes <= 29) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[24].style.display = 'block';
} else if (hour = 11, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[25].style.display = 'block';
} else if (hour = 23, minutes >= 30) {
document.getElementsByClassName("elInput elSelectInput elInput100 elAlign_left elInputMid elInputStyl0 elInputBG1 elInputBR5 elInputI0 elInputIBlack elInputIRight elInput-Select1 ceoinput required1 garlic-auto-save")[0].options[1].style.display = 'block';
}
}
</script>
</body>
</html>
спасибо
У тебя есть две проблемы в тебе условно if()
, первая состоит в том, что, если ты хочешь сравнить переменную hour
, должна быть двойная порция ==
такой hour==0
, иначе ты распределяешь в переменную стоимость.
Вторая проблема приходит с ','
внутри if()
, так как эта используется, чтобы отделять и оценивать с левой стороны до правой стороны, возвращая всегда последнюю стоимость. а именно то, что ты делаешь, состоит в том, чтобы распределять 0 в переменную hour
и оценивать последнюю condiciГіn только и она asignaciГіn harГЎ независимо от результата, deberГ-эксперта помещать &&
в Ваше место, чтобы показывать AND .
Смотрит эти примеры:
// supongamos que las funciones devuelven esto :
var hour = 0
var minutes = 28;
if (hour = 1, minutes <= 29) // aqui la consola muestra 1 por que es true la ultima evaluacion
console.log(hour);
В первом примере вторая condiciГіn выполняется и разворачивает 1
в консоли, и в этом втором примере он не выполняется и не вводит условную, но даже asГ - делается она asignaciГіn.
// supongamos que las funciones devuelven esto :
var hour = 0
var minutes = 30;
if (hour = 1, minutes <= 29) // en este caso la condicion es false pero se asigna el valor 1 de todas formas
console.log(hour+"No se muestra este resultado por que la condicion es falsa");
console.log(hour+" se asigna '1' a la variable independientemente del resultado");
это Принимает во внимание и - изменения для того, чтобы оно функционировало, именно поэтому никогда не переходи из второго if()
.
Хороший способ difГ-cil работать со столькими свободными переменными.
реализовал следующего cГіdigo решая твою проблему, хотя ты aconsejarГ, - в который ты изменил value
select
, и что сослались в часы, он однако реализует cГіdigo используя текст select.
<script type="text/javascript">
/* realizamos el ocultamiento de las options*/
var op = document.getElementById("time");
for (var i = 1; i < op.length; i++) {
op[i].style.display="none";
}
/* mostramos segun la hora*/
function timeSlot() {
var hour = new Date().getHours();
var minutes = new Date().getMinutes();
var op = document.getElementById("time");
for (var i = 1; i < op.length; i++) {
var hora = op[i].text.split(':');
if(hour == hora[0] && minutes >= 30 ){
op[i+1].style.display="block";
break;
}
else{
if(hour == hora[0]){
op[i].style.display="block";
break;
}
}
}
}
</script>
Remplaza cГіdigo, что у тебя есть в этикетках рукописный шрифт и deberГ, - чтобы функционировать.
типов привета!