How to store it in a variable?
I need to store the ReCaptcha code in a JavaScript variable and then dynamically show the captcha (in a dynamically created DIV). The problem is the following code cannot be开发者_JAVA百科 stored in a variable:
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k="></script><noscript><iframe src="http://www.google.com/recaptcha/api/noscript?k=" height="300" width="500" frameborder="0"></iframe><br/><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea><input type="hidden" name="recaptcha_response_field" value="manual_challenge"/></noscript>
I get the error in Firebug: unterminated string literal
. How to make it work?
You are probably storing it in a string using "
as the delimiters, which is clashing with the "
used on the attributes' value delimiters.
Try using single quote ('
), or escape each "
with a backslash (\"
) to have it treated literally.
var s = '<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k="></script><noscript><iframe src="http://www.google.com/recaptcha/api/noscript?k=" height="300" width="500" frameborder="0"></iframe><br/><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea><input type="hidden" name="recaptcha_response_field" value="manual_challenge"/></noscript>'
精彩评论