我试图在谷歌地图上展示一个标记。在Google中,我从ajax、set和infowindow的内容中获取数据。
infoWindowContent = [
['<div class="info_content"><h3>'+ this.tc_city_name + '</h3>'+ if this.tc_city_description !=='null'){ +'<p>' + this.tc_city_description + '</p>'} + '<p><a href = "' + this.tc_city_web_site + '" target="_blank">' + this.tc_city_web_site + '</a></p>'+ '</div>']
];这个代码当我使用if条件时,它会产生语法错误,请您告诉我,我是如何在这段代码中使用if条件的。
发布于 2014-11-05 09:46:42
使用+= 赋值算子向变量添加更多内容:
infoWindowContent = '<div class="info_content"><h3>' + this.tc_city_name + '</h3>';
if (this.tc_city_description !== 'null') {
infoWindowContent += '<p>' + this.tc_city_description + '</p>';
}
infoWindowContent += '<p><a href = "' + this.tc_city_web_site + '" target="_blank">' + this.tc_city_web_site + '</a></p>' + '</div>';顺便说一下,在您的(条件下,您缺少了一个if:
if (condition) {
// do something
}https://stackoverflow.com/questions/26750955
复制相似问题