2011-11-21 69 views
0

考虑这一行的JavaScript倒逗号 - PHP的JavaScript

str += "onclick=runTest(" + field + "," + atom[0] + ",'" + atom[1] + "'); 

的在浏览器中,它呈现为:

onclick="runTest(104,213,'Orsan" Miller'); 

有奥桑和米勒虽然事实上之间存在着一个倒逗号没有任何反向逗号,这是造成一个错误。

atom[1] = Orsan Miller 

'Orsan Miller'来自PHP中的DB查询。

这怎么解决?

+0

加速功能? – Jauzsika

+0

“引号逗号”也被称为引号:P – brianreavis

+0

是您的第一行javascript错字或者您是否真的错过了结束语? – ashansky

回答

2

你错过了一些引号和逃避......试试这个:

str += "onclick=\"runTest(" + field + "," + atom[0] + ",'" + atom[1] + "')\""; 

我更喜欢使用可读性单引号,但是这只是我:

str += 'onclick="runTest(' + field + ',' + atom[0] + ',\'' + atom[1] + '\')"'; 
0
str += "onclick=runTest(" + field + "," + atom[0] + ",'" + atom[1] + "')"; 

你正在寻找什么,除了你忘了最后的双引号之外没什么问题。