【发布时间】:2017-06-22 02:07:26
【问题描述】:
我正在从 JSON 创建一些 Google 地图标记,并且我想使用简写 if 语句来格式化内容。这是我现在拥有的:
infowindow.setContent('<strong>' + this.title + '</strong>' + this.description + '<a href="' + this.link + '" target="_blank">Website</a>');
所有标记都有标题,但有些可能有描述但没有链接或链接但没有描述。我怎样才能做到这一点,如果标记有链接和描述,它看起来像上面,如果它有一个链接但没有描述,它看起来像这样:
infowindow.setContent('<strong>' + this.title + '</strong>' + '<br/>' + '<a href="' + this.link + '" target="_blank">Website</a>');
如果它有描述但没有链接,则像这样:
infowindow.setContent('<strong>' + this.title + '</strong>' + this.description );
我知道我可以设置 3 个不同的 infowindow.setContent 函数,但我想知道是否有一种方法可以使用内联条件语句对一个函数执行此操作。
【问题讨论】:
标签: jquery google-maps conditional