你如何在 Meteor.js 中设置 html/body 标签属性? [英] How do you set html / body tag attributes in Meteor.js?

查看:38
本文介绍了你如何在 Meteor.js 中设置 html/body 标签属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 html 标签或 Meteor.js 应用程序中文档的 body 标签上设置属性.

I need to set attributes on the html tag or alternatively the body tag of the document in a Meteor.js application.

特别是我想要 ..

Specifically I want to have <html dir="rtl"> or <body dir="rtl">..

尝试后者,我收到控制台消息:

Trying the latter, I receive the console message:

While building the application:
client/views/layout/layout.html:7: Attributes on <body> not supported

=> Your application has errors. Waiting for file change.

那你是怎么做到的?

推荐答案

您必须在启动时在客户端 Javascript 中注入它们:

You have to inject them on start-up in your client-side Javascript:

Meteor.startup(function() {
   $('html').attr('dir', 'rtl');
});

更新

请注意,您现在可以为 body 标签设置内联属性,它们将通过 Meteor 以与 body 标签内容相同的方式连接:

Note that you can now set attributes in-line for body tags, and they'll be concatenated by Meteor in the same way as the contents of the body tag:

<body data-atttribute="foobar"></body>

你可以有多个不同的 body 标签,它们会组合在一起,所以上面的代码只会向你现有的 body 添加一个属性,而不是替换它.

You can have multiple different body tags, and they'll get combined, so the above will just add a single attribute to your existing body, rather than replacing it.

据我所知,HTML 标签属性仍然需要通过 Javascript 设置.

To the best of my knowledge, HTML tag attributes still need to be set via Javascript.

这篇关于你如何在 Meteor.js 中设置 html/body 标签属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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