简体   繁体   中英

javascript += operator

In my JSON javascript live pull I have:

    html += "<tr><td width=60 valign=top><a href='"+item.url+"' target='_blank'>"+item.site+"</a></td>";

The += seems to strip out my tr td values So I tried amending it to = which just seems to fail.. I tried setting td as a var and still no luck

Any ideas of a way round this, my js is basic so even if you think its silly your answer could help me greatly..

EDIT

to confuse things things further the = alone works in Firefox but on IE the items are loading hidden in the background.. I don't get why the browsers would perform so differently over the use of one + sign...

try:

html += "<tr><td width=60 valign=top><a href='"+item.url+"' target='_blank'>"+item.site+"</a></td></tr>";

Your markup generated is invalid (not closing the anchor tag) so it's possible the browser isn't interpreting the html very well.

x += y is just a shorthand for x = x + y . If you change it to html = "..." , you'd be overwriting anything that already existed in the html variable.

How are your "tr td values" being stripped?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM