【发布时间】:2014-03-03 19:58:54
【问题描述】:
我正在尝试比较 2 个字符串,但没有我想要的比较。我从 div 获取一个值并将其转换为字符串,当我发现它告诉我的 typeof 是一个字符串但它仍然通过 if 语句传递。
当我 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; ?>,缺少;并且缺少空格 -
题外话:你应该把
""+count改为increase the speed of execution,而不是String(count)。
标签: javascript php dom