开发者

html tidy and javascript regular expressions

开发者 https://www.devze.com 2023-03-25 18:13 出处:网络
When HTML Tidy see this HTML: <script type=\"text/javascript\"> var left =/</g </script> 开发者_Python百科It generates

When HTML Tidy see this HTML:

<script type="text/javascript">
    var left =  /</g
</script>
开发者_Python百科

It generates

<script type="text/javascript">
    var left =  /<\/g
</script>

which causes the run-time error: unterminated regular expression literal.

Is there a way to avoid this behavior? Thanks


Yes. Just avoid using </something in the script since it could confuse some browsers as closing tag. Use \x3c instead.

<script type="text/javascript">
    var left =  /\x3c/g
</script>
0

精彩评论

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