考虑下面这行JavaScript
str += "onclick=runTest(" + field + "," + atom[0] + ",'" + atom[1] + "'); 在浏览器中,它呈现为:
onclick="runTest(104,213,'Orsan" Miller');在Orsan和Miller之间有一个反逗号,虽然实际上没有任何反逗号,但它导致了一个错误。
atom[1] = Orsan Miller“'Orsan”来自PHP中的DB query。
如何解决这个问题?
发布于 2011-11-22 06:00:06
你漏掉了一些引号和转义...试试这个:
str += "onclick=\"runTest(" + field + "," + atom[0] + ",'" + atom[1] + "')\""; 为了可读性,我更喜欢使用单引号,但这只是我的情况:
str += 'onclick="runTest(' + field + ',' + atom[0] + ',\'' + atom[1] + '\')"';发布于 2011-11-22 06:05:34
str += "onclick=runTest(" + field + "," + atom[0] + ",'" + atom[1] + "')"; 就是你要找的东西,除了你忘了最后的双引号之外,一切都很好。
https://stackoverflow.com/questions/8219038
复制相似问题