无法在javascript中比较两个字符串 [英] Unable to compare two Strings in javascript
本文介绍了无法在javascript中比较两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JavaScript中尝试两个比较两个字符串。但我想在比较时有一些问题。它不显示结果。
I am trying two compare two strings in JavaScript. But I guess there is some problem while comparing. It doesn't show the results.
if(ajaxRequest.readyState == 4){
var msg = ajaxRequest.responseText;
var fld = document.getElementById("prtCnt");
if(msg == "false") {
var msg = "This User Name is already taken !!!!";
fld.className = "bp_invalid";
// fld.style.color=green;
fld.innerHTML=msg;
}
任何机构都可以告诉我问题在哪里?感谢。
Can any body tell me where the problem is? Thanks.
推荐答案
您可能想检查在从服务器返回的false字符串之前或之后是否有任何空格。您可以使用以下方法轻松完成此操作:
You might want to check if there's any space before or after the "false" string that you return from the server. You can do it easily with this:
alert('"' + msg + '"');
如果有额外的空间,您可以执行:
If there is extra space, you can just do:
msg = msg.trim();
然后执行if语句
这篇关于无法在javascript中比较两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文