Как определить, установлен ли флажок или нет в JavaScript

0

я хочу определить, что флажок установлен или нет, и я успешно делаю это сейчас, если пользователь снимет его, а затем как я могу это обнаружить? мой код - это

window.updated = function() {

    var x = document.getElementById("new").checked;
    if(x=true)
    {
        alert("true");
    }
    else
    {
         var tw1 = document.getElementById('tw1');

            tw1.value = '';
            document.getElementById('tw1').readOnly=false;
            //2nd

          tw2 = document.getElementById('tw2');    
            tw2.value = '';
            document.getElementById('tw2').readOnly=false;
            //3rd
         tw3 = document.getElementById('tw3');    
            tw3.value = '';
            document.getElementById('tw3').readOnly=false;
            //4th
         tw4 = document.getElementById('tw4');    
            tw4.value = '';
            document.getElementById('tw4').readOnly=false;
            //5th
         tw5 = document.getElementById('tw5');    
            tw6.value = '';
            document.getElementById('tw5').readOnly=false;
            //6th
         tw6 = document.getElementById('tw6');    
            tw6.value = '';
            document.getElementById('tw6').readOnly=false;
            //7th

      tw7 = document.getElementById('tw7');    
            tw7.value = '';
            document.getElementById('tw7').readOnly=false;
    }
             var ne1 = document.getElementById('ne1'),
          tw1 = document.getElementById('tw1');    
            tw1.value = ne1.value;
            document.getElementById('tw1').readOnly=true
            //2nd
              var ne2 = document.getElementById('ne2'),
          tw2 = document.getElementById('tw2');    
            tw2.value = ne2.value;
            document.getElementById('tw2').readOnly=true
            //3rd
              var ne3 = document.getElementById('ne3'),
          tw3 = document.getElementById('tw3');    
            tw3.value = ne3.value;
            document.getElementById('tw3').readOnly=true
            //4th
              var ne4 = document.getElementById('ne4'),
          tw4 = document.getElementById('tw4');    
            tw4.value = ne4.value;
            document.getElementById('tw4').readOnly=true
            //5th
              var ne5 = document.getElementById('ne5'),
          tw5 = document.getElementById('tw5');    
            tw5.value = ne5.value;
            document.getElementById('tw5').readOnly=true
            //6th
              var ne6 = document.getElementById('ne6'),
          tw6 = document.getElementById('tw6');    
            tw6.value = ne6.value;
            document.getElementById('tw6').readOnly=true
            //7th
              var ne7 = document.getElementById('ne7'),
          tw7 = document.getElementById('tw7');    
            tw7.value = ne7.value;
            document.getElementById('tw7').readOnly=true
    }

Если вы установите флажок, он будет помещать данные из входных данных платежных данных в входные данные о доставке.

Тем не менее, я всегда получаю true после снятия галочки, а также.

Теги:
checkbox

1 ответ

3
Лучший ответ

вы не сравниваете здесь свое назначение (x=true). это должно быть просто, if (x)

этот x = true присваивает значение true для x а затем оценивает его в выражении if. Вот почему это всегда верно
этот x == true возвращает true, если операнды равны.
это x === true возвращает true, если операнды равны и одного типа

  • 0
    хорошо, позволь мне
  • 0
    спасибо, что работает.
Показать ещё 2 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню