什么是脚本类型的现代使用=“text / html”并且这个例子好好使用吗? [英] What are modern uses of script type="text/html" and is this example cosidered good use?

查看:113
本文介绍了什么是脚本类型的现代使用=“text / html”并且这个例子好好使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像... ...

<script type="text/html" id="this-content1">
<h1>This Header Info One</h1>
<p>This content one. . .</p>
</script>
<script type="text/html" id="this-content2">
<h1>This Header Info Two</h1>
<p>This content two. . .</p>
</script>

...并使用jQuery根据今天标准中的选择器优秀实践来交换内容?

...and using jQuery to swap out the content based on a selector good practice in today's standards?

我刚刚开始使用 script type =text / html... 来允许动态更改我的内容找到很多方法来做到这一点。有没有一个来源可以解释这个方向,如果任何标准化这种做法。

I am just getting into the use of script type="text/html"... to allow dynamic changes of my content and am finding many ways to do this. Is there a source that might explain the direction this is going and if any standardizing of this practice.

我看到的代码就像...

I see code like...

<div class="thumbnail">
            <# if ( data.uploading ) { #>
                <div class="media-progress-bar"><div></div></div>
            <# } else if ( 'image' === data.type ) { #>
                <img src="{{ data.size.url }}" draggable="false" />
            <# } else { #>
                <img src="{{ data.icon }}" class="icon" draggable="false" />
            <# } #>
        </div>

...嵌套在一个脚本type =text / html它是这样写的。如果只是想在一个页面添加内容交换,它看起来有点重。

...nested in a script type="text/html" tag and really have no idea why it is written this way. Also have just wet my beak in backbone and this looks to be a little heavy if just looking to add content swapping in one page.

推荐答案

p>根据脚本标记的HTML5规范,它使用< script> 类型属性设置为任何有效的MIME类型完全kosher。包括 text / html text / plain 等MIME类型。

According to the HTML5 spec for the script tag, it's totally kosher to use <script> with a type attribute set to any valid MIME type. That includes MIME types like text/html or text/plain.

根据脚本标记的HTML4规范,它并不完全符合: / p>

According to the HTML4 spec for the script tag, it's not quite kosher:


有两种类型的脚本作者可能附加到HTML
文档:加载
[和t]软管,每次发生特定事件时执行

"There are two types of scripts authors may attach to an HTML document: Those that are executed one time when the document is loaded [and t]hose that are executed every time a specific event occurs"

模板。您可以使用jQuery或我的个人最爱, Mustache.js

You don't need backbone for templating. You can use e.g. jQuery or my personal favorite, Mustache.js.

这篇关于什么是脚本类型的现代使用=“text / html”并且这个例子好好使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆