开发者

JS code in HTML included with jQuery

开发者 https://www.devze.com 2023-02-21 00:48 出处:网络
I\'m using .html() to load a part of a code into an overlay div with jQuery. It works fine, until my HTML insert contains some s开发者_如何学运维ort of JS include:

I'm using .html() to load a part of a code into an overlay div with jQuery. It works fine, until my HTML insert contains some s开发者_如何学运维ort of JS include:

<script>someFunction</script>

Suddenly my code stops functioning in FF, Opera and Safari. IE does just fine. Any suggestions how to fix this?

Thanks.


If your JavaScript script is inside of a script tag on the page, then anywhere </script> appears, even inside of a string, will close the script block. Try putting your script inside of an external file instead. If that doesn't work, you can do some trickery, like having a string like this:

"<script>/* Do stuff */</sc" + "ript>"


I attempted this code on a simple jQuery based page, which is similar to what you are doing:

$(document.body).append('<script type="text/javascript">alert("hello");</script>')

And it worked. I suspect that your someFunction code may have an error in it. Maybe you can post the code in question?

0

精彩评论

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