My page is a jsp page, which contains a parameter: lefttree,
This lefttree is spelled out from the background, and the content is html code: such as:
The code copy is as follows:
<div onclick="show('tt1','abc')">
In the jsp page, you need to pay this value to a div through the js code, as follows:
The code copy is as follows:
<script type="text/javascript">
window.parent.document.getElementById('mptree').innerHTML='<%=lefttree%>';
<script>
In this way, since lefttree contains both single quotes and double quotes, a matching error occurs with the outermost single quote when assigning values in js, it becomes:
The code copy is as follows:
'<div onclick="show('tt1','abc')">'
Solution:
Use escape characters "/"
When splicing lefttree in the background, it becomes the following form:
The code copy is as follows:
<div onclick="show(///'tt1///',//'abc///')">
in:
The first two "//" are used to keep the next "/" in the page
The third "/" is used to escape the single quotes afterwards.
In this way, the value of lefttree is:
The code copy is as follows:
<div onclick="show(/'tt1/',/'abc/')">