html 脚本标签未使用类型 javascript <script type="text

6

本文介绍了html 脚本标签未使用类型 javascript <script type="text/html>>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在一个 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 &lt;script type=&quot;text/html&gt;&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14