首页 > 使用script标签加载html页面的问题

使用script标签加载html页面的问题

页面a:

页面b:

我现在在a的页面里面使用
<script src="js/table.html" type="text/html" id="demo"></script>
引用后调试工具能显示出里面的内容

但是该怎么取出来呢?是哪里有问题呢?

我做这个的目的就是想自己写个模板引擎。虽然编写一个简单的JavaScript模板引擎--廖雪峰这个文章挺有用的,但有一点不明白的是,模板里的页面必须要放在页面里吗?不能单独放在一个页面里引用进来呢?

很多教程都是这样写的。

但是我想将这一块:

单独放在一个页面不行吗?还是我的使用,引用方式有错误呢?求解。




这个是参考MDN对script的介绍,我的理解是它只能加载脚本文件,类型都是js,在类型不是js的情况下,会被当做数据块,而不被浏览器处理,下面是MDN具体的内容:
type
This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is **specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript.** If this attribute is absent, the script is treated as JavaScript.
script标签只是加载脚本文件,没有说可以加载.html文件
If the MIME type specified is not a JavaScript type the content embedded within its tags is treated as a data block which won't be processed by the browser.

用load()方法可以


可以通过ajax以text请求得到html内容。

【热门文章】
【热门文章】