开发者

How to store it in a variable?

开发者 https://www.devze.com 2023-02-28 15:29 出处:网络
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

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>'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号