简体   繁体   English

如何在已由外部 javascript 文件生成的 html 页面中运行脚本标签

[英]How can run a script tag in html page which is already generated by an external javascript file

extenal javascript file: var someVariable="document.write('JavaScript text');";外部 javascript 文件:var someVariable="document.write('JavaScript text');";

and output should be: JavaScript text和 output 应该是: JavaScript 文本

You can't do that with document.write().你不能用document.write(). write() only gets executed once. write()只执行一次。 For other javascript functions you use eval() but again it won't work for write()对于其他 javascript 函数,您使用eval()但它再次不适用于write()

code is:代码是:

<html>
<head>
    <title>JavaScript</title>
        <script type="text/javascript">
            var somevariable="<script>document.write('This is a javascript variable');</script>";
        </script>
    </head>
<body>
    <script type="text/javascript">
        document.write(somevariable);
    </script>
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Javascript 模块从外部 javascript 文件导入<script> tag of HTML file - How to Import Javascript Module from external javascript file into <script> tag of HTML file 通过src标记在html页面中包含外部javascript文件 - Including external javascript file in html page via src tag 如何在div标记内的document.writes()html块进行异步回发时重新加载外部javascript文件? - How to Reload external javascript file on asynchronous postback which document.writes() html block inside a div tag? 你怎么看到哪个Javascript脚本生成了某个html行? - How can you see which Javascript script generated a certain html line? 如何将 HTML 脚本标签复制到外部 javascript? - How do I copy HTML script tag to external javascript? 使用HTML中的外部Javascript文件运行PHP脚本 - Run PHP Script using an external Javascript file in HTML 在脚本标签内的其他HTML文件中运行JavaScript函数 - Run JavaScript Function in a different HTML file inside a script tag html页面中的javascript脚本块可以在标头中使用,但不能从外部文件中使用 - javascript script block in html page works in header but not from external file <script> tag is not working i am trying to run javascript script in script tag in html file - <script> tag is not working i am trying to run javascript script in script tag in html file 我如何*本地*保存由javascript生成的.html文件(在* local * .html页面上运行)? - How can I *locally* save an .html file generated by javascript (running on a *local* .html page)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM