简体   繁体   English

javascript + =运算子

[英]javascript += operator

In my JSON javascript live pull I have: 在我的JSON javascript live pull中,我有:

    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 + =似乎删除了我的tr td值,所以我尝试将其修改为=似乎失败了。

Any ideas of a way round this, my js is basic so even if you think its silly your answer could help me greatly.. 关于此问题的任何想法,我的js都是基础知识,因此即使您认为其愚蠢的答案也可以对我有很大帮助。

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... 更令人困惑的是,= =仅在Firefox中有效,但在IE上,这些项目隐藏在后台。.我不明白为什么浏览器在使用+号时会表现得如此不同...

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. 您生成的标记无效(未关闭锚标记),因此浏览器可能无法很好地解释html。

x += y is just a shorthand for x = x + y . x += y只是x = x + y的简写。 If you change it to html = "..." , you'd be overwriting anything that already existed in the html variable. 如果将其更改为html = "..." ,则将覆盖html变量中已经存在的所有内容。

How are your "tr td values" being stripped? 如何去除“ tr td值”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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