There is actually no difference between single quotes and double quotes, it depends on your getting used to it.
The code copy is as follows:
<input type="button" onclick="alert("1")">------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<input type="button" onclick="alert('1')">------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Use double quotes in double quotes like this:
var str = "abc/"def/"ghi"
Use backslashes to disable double quotes.
Here is an excerpt from me, I hope it will be useful to you:
In a button in a web page, write the onclick event processing code, accidentally written as follows:
The code copy is as follows:
<input value="Test" type="button" onclick="alert(""OK"");" />
After the IE prompt error occurs, it casually changes to:
The code copy is as follows:
<input value="Test" type="button" onclick="alert(/"OK/");" />
The result is still an error.
At this time, I couldn't figure it out, although I knew the most direct solution was to write it like this:
The code copy is as follows:
<input value="" type="button" onclick="alert('OK');" />
But why are the escape characters/free in javascript?
Later I found a normal code:
The code copy is as follows:
<input value="Test" type="button" onclick="alert("OK");" />
Only then did I understand that it was still within the jurisdiction of HTML at this time, so the escape characters should be used in HTML, not in JavaScript. The two double quotes are vbScript, /"This method is javascript, and HTML, it is used", and you can also use: ",'.
The following are various expression methods:
The code copy is as follows:
<html>
<body>
<input value="outer double quotes inside double quotes-error" type="button" onclick="alert("OK");" /><br />
<input value="external quotes inside single quotes-error" type="button" onclick='alert('OK');' /><br />
<input value="two double quotes-error" type="button" onclick="alert(""OK"");" /><br />
<input value="two single quotes-error" type="button" onclick="alert(''OK'');" /><br />
<input value="/+Double Quotes - Error" type="button" onclick="alert(/"OK/");" /><br />
<input value="/+single quotes-error" type="button" onclick="alert(/'OK/');" /><br />
<input value="outer double quotes inside single quotes-OK" type="button" onclick="alert('OK');" /><br />
<input value="external quotes and double quotes inside -OK" type="button" onclick='alert("OK");' /><br />
<input value="No quotes used outside -OK" type="button" onclick=alert('OK');alert("OK"); /><br />
<input value="HTML escape character"(& # 3 4 ;)-OK" type="button" onclick="alert("OK");" /><br />
<input value="HTML escape character'(& # 3 9 ;)-OK" type="button" onclick="alert('OK');" /><br />
<input value="HTML escape character"(& # x 2 2 ;)-OK" type="button" onclick="alert('OK');" /><br />
<input value="HTML escape character'(& # x 2 7 ;)-OK" type="button" onclick="alert('OK');" /><br />
<input value="HTML escape character"(& quot ;)-OK" type="button" onclick="alert("OK");" /><br />
<input value="HTML escape character"(& apos ;)-IE error" type="button" onclick="alert('OK');" /><br />
<input value="Other//-Error" type="button" onclick="alert(//"OK//");" /><br />
<input value="Other/& # 3 4 ;-Error" type="button" onclick="alert(/"OK/");" /><br />
</body>
</html>