[英]Comparision of two equal strings returns false
Here is my line: 这是我的路线:
myArray[i].innerText == x
Here are the values from Chrome console: 以下是Chrome控制台的值:
myArray[i] = "13 ml Apollo glaze sherry truffel 250ml" myArray [i] =“13毫升阿波罗釉雪利酒松露250毫升”
x = "13 ml Apollo glaze sherry truffel 250ml" x =“13毫升阿波罗釉雪利酒松露250毫升”
myArray[i].innerText == x returns false Why is this happening? myArray [i] .innerText == x返回false为什么会发生这种情况?
Here is how I define myArray: 以下是我定义myArray的方法:
myArray= $($('#myIframe').contents()).find('body#tinymce').find('p, li');
debug it, you most likely have some extra whitespace characters in it. 调试它,你很可能有一些额外的空白字符。
console.log(escape(myArray[i].innerText));
You probably need to trim it . 你可能需要修剪它 。
Or the HTML entities are there. 或者HTML实体在那里。
var replacedString = myArray[i].innerText.replace(/ /g," ");
If you have a bunch of special characters, you will need to replace them all. 如果你有一堆特殊字符,你需要全部替换它们。
You aren't comparing two strings. 你没有比较两个字符串。
You are comparing a string with the innerText
property of an identical string 您正在将字符串与相同字符串的
innerText
属性进行比较
myArray[i] === x
It looks like you should compare myArray[i]
rather than myArray[i].innerText
, seeing as that is what you assign to. 看起来你应该比较
myArray[i]
而不是myArray[i].innerText
,因为这就是你所分配的内容。 myArray[i].innerText
will always yield undefined
, if myArray[i]
is a string (unless you're doing some weird prototyping). 如果
myArray[i]
是一个字符串(除非你做了一些奇怪的原型设计), myArray[i].innerText
总是会产生undefined
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.