javascript - 使用script标签加载html页面的问题
阿神
阿神 2017-04-11 10:32:22
[JavaScript讨论组]

页面a:

页面b:

我现在在a的页面里面使用

引用后调试工具能显示出里面的内容

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

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

很多教程都是这样写的。

但是我想将这一块:

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

阿神
阿神

闭关修行中......

全部回复(3)
PHPz

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

ringa_lee

用load()方法可以

黄舟


这个是参考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.
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号