这个问题看起来有点愚蠢......但我想知道是否可以将内联 javascript 代码插入另一个 javascript 代码。让我们说清楚:
我正在尝试放置一个 google plus 按钮,通过 jquery 将其附加如下:
jQuery('.gplus').append('<g:plusone annotation="inline"></g:plusone>');
此按钮需要外部 js 才能正常工作。我想要做的是插入外部js这样做:
var gplusjs = '
<script type="text/javascript">
(function() {var po = document.createElement("script");
po.type = "text/javascript"; po.async = true;
po.src = "https://apis.google.com/js/plusone.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);
})();
</script>';
jQuery('#js').append(gplusjs);
其结果是将代码打印为 HTML,但不解释为脚本。这个有可能?我是个笨蛋?谢谢!