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

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

问题描述

类似......

 < script type =text / htmlid =this-content1 > 
< h1>此标题信息一< / h1>
< p>此内容之一。 。 < / p为H.
< / script>
< script type =text / htmlid =this-content2>
< h1>此标题信息二< / h1>
< p>此内容二。 。 < / p为H.
< / script>

...并使用jQuery根据当今标准中的选择器优良做法交换内容?



我刚开始使用 script type =text / html... 来允许动态更改我的内容。找到许多方法来做到这一点。是否有一个来源可以解释这个过程的方向,以及是否对这种做法进行了标准化。



我看到类似...的代码...

 < 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 =icondraggable =false/>
<#}#>
< / div>

...嵌套在脚本类型=text / html标签中,真的不知道为什么它是这样写的。也可以在我的主干上弄湿我的喙,如果只是想在一个页面上添加内容交换,这看起来有点沉重。 解决方案

p>根据脚本的 HTML5规范标记,使用< script> 并将类型属性设置为任何有效的MIME都是完全可以的类型。这包括MIME类型,如 text / html text / plain



根据脚本标记的 HTML4规范,它不是很好:


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


您不需要骨架模板。您可以使用例如jQuery或我个人的最爱, Mustache.js

Is something like...

<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>

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

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>

...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.

解决方案

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

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

"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"

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

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

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