Javascript属性比较

时间:2016-05-28 01:15:34

标签: javascript string

我试图检查输入控件中的值和元素中属性的值是否相同。当两个值都是空字符串时,我得到的结果为true,这基本上是说空字符串不等于空字符串。这是不正确的,我的结果变量应该是假的。

var result = txtEntryPhone.value != selectedMember.Phone;

image

1 个答案:

答案 0 :(得分:0)

可以检查:

其中一个值是否包含不可见的字符?检查长度以确认:

    def fullname
        "#{first_name} #{last_name}"
    end

    puts "Enter your first and last name (John Doe): "
    name=gets.to_s
    names=name.split(" ", 2)
    puts "Enter your email address (joe@info.com): "
    email=gets
    puts "Enter your phone number including area code (numbers only): "
    number=gets.to_i

     def valid_email(email)
        email=email.to_s
        email="user@company_name.com"
        loop do
          if (email=/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i)
          break
          else
          puts "Invalid email address entered. Please try again. "
          end
        end
    end

    def phone_number(number)
        number        = number.to_s

        area_code     = number.length == 10 ? "(#{number[0..2]}) " : '' 

        office_code   = number[-7..-5] 
        specific_line = number[-4..-1]
    loop do
        if number =10
        break   
            else
            puts "Invalid phone number entered. Please try again."
            end
        end
        "#{area_code}#{office_code}-#{specific_line}"
    end

    puts names
    puts valid_email(email)
    puts phone_number(number)

如果两个元素都对象,例如console.log(txtEntryPhone.value.length); console.log(selectedMemeber.Phone.length);

...value = new String('')