html script tag not using type javascript lt;script type=quot;text/htmlquot;gt;?(html 脚本标签未使用类型 javascript lt;script type=quot;text/htmlgt;gt;?)
问题描述
我在一个 html 页面上查看源代码并遇到了这个
I was checking out the source on an html page and came across this
<script id="searchItemTemplate" type="text/html">
<# var rows = Math.floor((Model.RecordsPerPage - 1) / 3 + 1);
for (var i = 0; i < rows; ++i){
var startIdx = i * 3;
var endIdx = startIdx + 3;
#>
//etc ....
</script>
我以前从未见过这个.什么是脚本 type="text/html".我不知道这是否有区别,但这是在 .aspx 页面上.
I have never seen this before. What is script type="text/html". I don't know if it makes a difference but this was on a .aspx page.
这是某种稍后要解析和 eval() 的占位符吗?
有谁知道这是什么?
使用过这种方法的人可以解释一下好处吗?
推荐答案
简单地忽略具有未知内容类型的脚本元素,在这种情况下,浏览器不知道如何执行 text/html 脚本.
Script elements that have an unknown content-type are simply ignored, in this case, the browser doesn't know how to execute a text/html script.
这是一些 JavaScript 模板引擎常用的技术.
It's a common technique used by some JavaScript templating engines.
另见:
- JavaScript 微模板
- JavaScript 模板引擎
这篇关于html 脚本标签未使用类型 javascript <script type="text/html>>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:html 脚本标签未使用类型 javascript <script type="text/html>>?
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
