简体   繁体   English

两个相等字符串的比较返回false

[英]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.

相关问题 JavaScript:字符串相等但比较返回false - JavaScript: Strings are equal but comparing returns false 虽然两个值相等,但返回false - Though two values are equal returns false 在JQuery中比较两个相同的字符串将返回false - Comparing two identical strings in JQuery returns false Ember.computed.equal在相同的字符串上返回false - Ember.computed.equal returns false on identical strings 比较两个相等节点的childNodes返回false,比较它们的innerHTML返回true,为什么? - Comparing two equal nodes' childNodes returns false, comparing their innerHTML returns true, why? 谁能解释这是怎么回事? 比较时两个相等的字符串返回false - Can anyone explain whats going on here? Two equal strings return false when compared 字符串相等时,字符串相等返回false - String equality returning false when strings are equal 两个看似相等的字符串在javascript中不相等 - Two seemingly equal strings not equal in javascript JavaScript:两个相等的字符串不相等 - JavaScript: two equal strings not being equal 比较2个看似相等的字符串会返回false,因为一个以char代码8291结尾的字符串。如何清理字符串? - Comparing 2 seemingly equal strings returns false because one ends with char code 8291. How can I sanitize the string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM