首页 > 解决方案 > Wemassembly 设置元标记

问题描述

我正在尝试设置元标记。

<meta name="description" content="text here"/>

这是我尝试过的,但它不起作用,也不会导致任何错误。

js.Global().Get("document").Set(`meta[name="description"]`, "new text here")

有什么建议么?

标签: javascripthtmlwebassembly

解决方案


我认为您当前所做的与document["meta[name=\"description\"]"] = "new text here"JavaScript 中的相同,它并没有做您想要的。

您需要的可能是这样的:

document.querySelector(`meta[name="description"]`).content = "new text here"

您可以使用Call实际选择您的元素querySelector,然后content像这样设置它的属性:

js.Global().Get("document").Call("querySelector", `meta[name="description"]`).Set("content", "new text here")

推荐阅读