javascript if语句传递的是真值

时间:2013-12-02 10:53:25

标签: javascript jquery

这是数据,

<tr>
    <td>
    <input type="checkbox" class="internal_case">
    </td>
    <td style="display:none;">0</td>    
</tr>

你必须看到的是第二个td带有“0”值。

现在我制作了像这样的javascript代码,

$("#invited_table tr").each(function() {
                var memberFlag = false; // if memberFlag = false -> internal, memberFlag = true -> external
                var internal = {
                    id : "",
                    firstname : "",
                    lastname : "",
                    email : "",
                    moderator : "",
                };
                var external = {
                    id : "",
                    firstname : "",
                    lastname : "",
                    email : "",
                    timezone : ""
                };
                $(this).find('td').each(function(index, obj) {
                    //console.log($(this).find('input').prop("checked",true));
                    //console.log(obj.innerHTML);
                    //console.log($('#invited_table :radio:checked'));
                    // check that the radiobutton is checked
                    //console.log($(this).find('input').is(':checked'));
                    //console.log(obj.innerHTML);
                     switch(index) {
                        case 1:
                        //id seperate condition to external=0 or internal others
                        if(obj.innerHTMl=="0"){
                            memberFlag = true; // memberflag true means, external
                            external.id = obj.innerHTML;
                        }else{
                            internal.id = obj.innerHTML;
                        }       
                            break;
                        // case 1:
                            // //id
//                              
                            // invitedPeopleHTML += "<td style='display:none;'>" + obj.innerHTML + "</td>";
                            // attendee.id = obj.innerHTML;
                            // // classify value, if it is internal, put member
                            // invitedPeopleHTML += "<td>Member</td>";
                            // break;
                        case 3:
                            //firstname
                            if(!memberFlag){
                                //internal
                                internal.firstname = obj.innerHTML;
                            }else{
                                //external
                                external.firstname = obj.innerHTML;
                            }

                            break;
                        case 4:
                            //lastname
                            if(!memberFlag){
                                //internal
                                internal.lastname = obj.innerHTML;
                            }else{
                                //external
                                external.lastname = obj.innerHTML;
                            }
                            break;
                        case 5:
                            //email
                            if(!memberFlag){
                                //internal
                                internal.email = obj.innerHTML;
                            }else{
                                //external
                                external.email = obj.innerHTML;
                            }
                            break;
                        // // if internal, timezone doesn't have to be inserted.
                        // // case 5://timezone
                        // // invitedPeopleHTML += "</tr>";
                        // // attendee.timezone  = obj.innerHTML;
                        // // break;
                        case 6:
                            if(!memberFlag){
                                // only check the radion button, if it is internal
                                var checked = $(this).find('input').is(':checked');
                                internal.moderator = checked;
                            }
                            break;
                        case 8:
                            if(memberFlag){
                                // only check the timezone, if it is external
                                external.timezone = obj.innerHTML;
                            }
                        break;
                     }

                 });
                // temp paused
                //add_inviteList(attendee.id, attendee.firstname, attendee.lastname, attendee.email);
                if(!memberFlag){
                    attendee_list.push(internal);   
                }else{
                    attendee_list.push(external);
                }

            });

这是一个很长的代码,但我们只需要专注于

case 1:
                        //id seperate condition to external=0 or internal others
                        if(obj.innerHTMl=="0"){
                            memberFlag = true; // memberflag true means, external
                            external.id = obj.innerHTML;
                        }else{
                            internal.id = obj.innerHTML;
                        }      

我真的检查过obj.innerHTML是0!所以if语句必须在if条件旁边,但是它会转到else条件:(

这是调试截图。

enter image description here

正如你在这里看到的那样,它肯定会变得真实!但它会变成虚假状态。这让我疯了:(

1 个答案:

答案 0 :(得分:2)

您的if行中有一个拼写错误 - obj.innerHTMlL是小写的 - 应该更高):

有效的一个:

if(obj.innerHTML=="0")