1
我想比较2个字符串,但没有比较,因为我想。我从一个div中获取一个值并将其转换为一个字符串,当我发现它告诉我的字符串是一个字符串,但它仍然通过if语句传递。试图比较2字符串,如果语句
当我write.document他们都看起来一样。 感谢
<div id="countries"><?php $geoplugin->locate(); echo"{$geoplugin->countryName}"?> </div>
<script>
var country = document.getElementById("countries");
var count = country.innerHTML;
var newc = String(count);
if (newc === "Ireland"){
document.write("this is ireland");
alert("You are from Ireland");
}else{
document.write("You Live in " + newc);
//alert(typeof newc);
//alert(newc);
}
</script>
'<?php $ geoplugin-> locate(); echo“{$ geoplugin-> countryName}”?>'应该是'<?php $ geoplugin-> locate(); echo $ geoplugin-> countryName; ?>'',缺少';'和空白空间 – DanFromGermany
焦虑问题:您应该使用'“”+ count'来提高执行速度(http://jsperf.com) /类型转换变量)。 –