Jump to content
php.lv forumi
  • 0

JavaScript gluks vai mana likrocība


Wuu

Question

Šādi strādā.

function sendvote() {
if(document.voteform.vote[0].checked == 'true') { send('040 1'); }
if(document.voteform.vote[1].checked == 'true') { send('040 2'); }
}

 

Bet šādi nē!

function sendvote() {
if(document.voteform.vote[0].checked == 'true') { send('040 1'); } else { send('040 2'); }
}

 

Noņēmos zils no dusmām!

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
checked Property

This property is a boolean value that sets or returns the current state of the Checkbox object; true if checked and false otherwise.

 

Attiecīgi izteiksme:

document.voteform.vote[0].checked == 'true'

pārbauda vai īpašība "checked" kā tips String ir vienāda ar virkni "true", kas protams nav pareizi, jo "checked" atgriež Boolean. Vajdzētu darboties jebkuram no šiem variantiem:

if (document.voteform.vote[0].checked == true) {}
if (document.voteform.vote[0].checked) {}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...