jquery - put "<script>" in a variable in JavaScript - Stack Overflow

I want to put "<script>" in a variable in JavaScript but it will be consider as end ta

I want to put "</script>" in a variable in JavaScript but it will be consider as end tag like below example:

<script>     
content.value = aval + '<script> ma_gallery("' + varimgurl + '");</script>'+ sevom;
</script>

Does anyone know a solution ?

I want to put "</script>" in a variable in JavaScript but it will be consider as end tag like below example:

<script>     
content.value = aval + '<script> ma_gallery("' + varimgurl + '");</script>'+ sevom;
</script>

Does anyone know a solution ?

Share Improve this question asked Jul 22, 2014 at 16:03 SamSam 1,5791 gold badge14 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 17

Use '<\/script>'.

In a string literal, an escaped slash is equivalent to a slash so it makes no difference to the JavaScript parser but it breaks up the end tag syntax so it isn't parsed as an end tag by the HTML parser.

(An alternative is to split it up into two strings and concatenate them together, but that is more typing, harder to read, and (albeit not significantly) less efficient).

Split "</script>" into two strings:

content.value = aval + '<script> ma_gallery("' + varimgurl + '");</scr' + 'ipt>' + sevom;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744146656a4560455.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信