admin管理员组文章数量:1323200
I am facing issue when I try to insert space using .html()
method in JQuery.
Following is my code :
html += '<td >'+description+". "+location;
html += +" "+position;
html += +" "+side+'</td>';
$('#tempResult').html(html);
The result I am getting is as follows:
Green Tint. 0FrontNaNRight
I am facing issue when I try to insert space using .html()
method in JQuery.
Following is my code :
html += '<td >'+description+". "+location;
html += +" "+position;
html += +" "+side+'</td>';
$('#tempResult').html(html);
The result I am getting is as follows:
Green Tint. 0FrontNaNRight
2 Answers
Reset to default 9Remove the +
operator from your string. +=
takes care of the string concatenation, so the additional +
sign simply tries to make the string positive (causing the interpreter to change it to NaN
- not a number).
a += b
is a "shorthand way" (perhaps a simplification) of saying a = a + b
.
html += '<td >'+description+". "+location;
html += " "+position;
html += " "+side+'</td>';
$('#tempResult').html(html);
The += + bit is doing some type conversion. Get rid of the 2nd +.
Another way of building html is via arrays and joining. One example:
var description = 'DESCRIPTION',
location = 'LOCATION',
position = 'POSITION',
side = 'SIDE',
html = [
'<td>' + description,
'. ' + location,
' ' + position,
' ' + side,
'</td>'
];
$('#tempResult').html(html.join(''));
本文标签: javascriptHow to insert space in htmlStack Overflow
版权声明:本文标题:javascript - How to insert space in html? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742097723a2420652.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论