来自json的URL添加一个尾部斜杠

时间:2015-05-15 16:10:36

标签: javascript json

我有一个包含URL的JSON元素:

imgRow += "<td><img src=" + item.style.stockPhotoUrl + "/></td>";

但是当我尝试在我的javascript中使用它时:

<td>
    <img src="http://media.xyz.com/Data/stockPhotos/17962.jpg/"/>
</td>

结果是:

@link-hover-color: lightblue; //Change this to your needs
a{  
color: @link-color;
&:hover{
    color: @link-hover-color;
}
&:hover, &:focus{
    text-decoration: none;
}
&:visited:not(.btn){
    color: @link-visited-color;
}

// Exceptions to :visited state
// Comment out to taste
&.list-group-item:visited{
    color:@list-group-link-color;
    &.active,
    &.active:hover,
    &.active:focus {
        color: @list-group-active-color;
    }
}
.navbar-default &.navbar-brand:visited{
    color:@navbar-default-brand-color;
}
.navbar-inverse &.navbar-brand:visited{
    color:@navbar-inverse-brand-color;
}
.nav-tabs > li > &:visited{
    color: @link-color;
}
.nav-pills > li > &:visited{
    color: @link-color;
}
.nav-pills > li.active > &:visited{
  &,
  &:hover,
  &:focus {
    color: @nav-pills-active-link-hover-color;
  }
}
.dropdown-menu > li > &:visited{
   color: @dropdown-link-color;
  &:hover,
  &:focus {
    color: @dropdown-link-hover-color;
    background-color: @dropdown-link-hover-bg;
  }
}
.dropdown-menu > li.disabled > &:visited{
  &,
  &:hover,
  &:focus {
    color: @dropdown-link-disabled-color;
  }
}
.pager > li > &:visited,
.pagination > li > &:visited{
    &,
    &:hover,
    &:focus {
        color: @link-color;
    }
}
.pagination > .active > &:visited{
    &,
    &:hover,
    &:focus {
        color: @pagination-active-color;
    }
}
.pagination > .disabled  > &:visited{
    &,
    &:hover,
    &:focus {
        color: @pagination-disabled-color;
    }
}
&.alert-link:visited{
    color: inherit;
}
}

我不确定为什么会添加一个尾部斜杠。

我怎么能摆脱这个斜线?

1 个答案:

答案 0 :(得分:4)

HTML tag attributes应该用双引号括起来。

您获得的行为可能是未包装src属性的产物。尝试将您的javascript修改为:

imgRow += "<td><img src=\"" + item.style.stockPhotoUrl + "\"/></td>";

或者,使用单引号表示字符串:

imgRow += '<td><img src="' + item.style.stockPhotoUrl + '"/></td>';