সহায়তা খুঁজুন

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

What about attribute 'checked' of input? What i should do: "removeAttribute('checked')" or "checked = false"?

  • 5 উত্তরসমূহ
  • 2 এই সমস্যাটি আছে
  • 13 দেখুন
  • শেষ জবাব দ্বারা cor-el

more options

SCRIPT function vibor(){ if (document.getElementById('autologin').checked = true){ document.getElementById('autologin').removeAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left top'; } else { document.getElementById('autologin').createAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left bottom'; } } /SCRIPT If i used "removeAttribute", in face input is checked. But if i used "checked = false", input's face not checked, but it checked in HTML code (if FireBug don't lies). Please, helped me somebody! I don't know what i should do.

P.s. Please, don't scold me for my English. I don't speak English very much and that have a cause - i'm 14 years old and lived in Russia, where nobody may helped me.

SCRIPT function vibor(){ if (document.getElementById('autologin').checked = true){ document.getElementById('autologin').removeAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left top'; } else { document.getElementById('autologin').createAttribute('checked'); document.getElementById('autologin1').style.backgroundPosition = 'left bottom'; } } /SCRIPT If i used "removeAttribute", in face input is checked. But if i used "checked = false", input's face not checked, but it checked in HTML code (if FireBug don't lies). Please, helped me somebody! I don't know what i should do. P.s. Please, don't scold me for my English. I don't speak English very much and that have a cause - i'm 14 years old and lived in Russia, where nobody may helped me.

সমাধান চয়ন করুন

It is not an attribute, but a Boolean JavaScript variable and you can't remove it.

Note that if (document.getElementById('autologin').checked = true){} will set that variable always to true.

You probably want this:

function vibor(){
 if (document.getElementById('autologin').checked == true){
   document.getElementById('autologin').checked = false;
   document.getElementById('autologin1').style.backgroundPosition = 'left top'; 
 } else {
   document.getElementById('autologin').checked = true;
   document.getElementById('autologin1').style.backgroundPosition = 'left bottom';
   }
} 
প্রেক্ষাপটে এই উত্তরটি পড়ুন। 👍 1

All Replies (5)

more options

Если есть кто-то русскоговорящий, то объясняю: при использовании removeAttribute удаляется сам атрибут checked, но галочка на виду остаётся. А при юзании checked = false галочка убирается только на виду, но остаётся в html'e. Юзать обе функции одновременно?

more options

А, хотя сам уже разобрался, знаете ли. Просто checked как атрибут задаёт отметку по умолчанию4 если кто не знает - напишу на всякий случай. Тему можно фтопку.

more options

চয়ন করা সমাধান

It is not an attribute, but a Boolean JavaScript variable and you can't remove it.

Note that if (document.getElementById('autologin').checked = true){} will set that variable always to true.

You probably want this:

function vibor(){
 if (document.getElementById('autologin').checked == true){
   document.getElementById('autologin').checked = false;
   document.getElementById('autologin1').style.backgroundPosition = 'left top'; 
 } else {
   document.getElementById('autologin').checked = true;
   document.getElementById('autologin1').style.backgroundPosition = 'left bottom';
   }
} 
more options

cor-el, thank you! I used this code and don't have a problem. This is checkbox of autologin to forum "Лунная студия" (moon studio) and that looks very beautiful! Again thank you!

more options

You're welcome.