如何在JavaScript中正确使用引号?
在我的JavaScript代码中,我有以下行:如何在JavaScript中正确使用引号?,javascript,html,quotation-marks,Javascript,Html,Quotation Marks,在我的JavaScript代码中,我有以下行: document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed('test')'>Se resultat</button>"); 将它们更改为转义双引号应该适合您 document.
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed('test')'>Se resultat</button>");
将它们更改为转义双引号应该适合您
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed(\"test\")'>Se resultat</button>");
document.write(“Se resultat”);
将它们更改为转义双引号应该对您有用
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed(\"test\")'>Se resultat</button>");
document.write(“Se resultat”);
您可以将单引号更改为转义双引号:
onclick='Proceed(\"test\")'
您可以将单引号更改为转义双引号:
onclick='Proceed(\"test\")'
它不起作用,因为它是无效的HTML:
document.write("</form><button ... onclick='Proceed('test')'>...</button>");
或:
document.write(“…”);
编辑:请参见一个简单的示例,它不起作用,因为它是无效的HTML:
document.write("</form><button ... onclick='Proceed('test')'>...</button>");
或:
document.write(“…”);
编辑:有关一个简单的示例,请参见手动创建这些元素,而不是使用document.write()
将缓解该问题。目前的共识是首先避免使用document.write()
。如果“手动”而不是使用document.write()
创建这些元素,则可能会出现重复,这将缓解该问题。目前的共识是首先要避免使用document.write()
。在继续函数中更改“to\”并删除关键字var
,这可能是重复的操作。谢谢!:)在继续函数中更改“to\”并删除关键字var
,这使它工作起来。谢谢!:)
document.write("</form><button ... onclick='Proceed(\"test\")'>...</button>");