How can I properly escape JavaScript in JavaScript?
问题 This might be something I can't do but... parent.document.getElementById('<?php echo $_GET['song']; ?>') .innerHTML = '<img src="heart.png" onmouseover="heartOver('');" >'; The onmouseover="heartOver(''); portion breaks my JavaScript. Is there a way to escape the quotes so I can do this? 回答1: Escape nested quotes with a backslash: \' Also, never echo user data without validating or sanitizing it: $song = $_GET['song']; // Validate HTML id (http://www.w3.org/TR/REC-html40/types.html#type-name)