【发布时间】:2020-12-29 10:32:07
【问题描述】:
我正在尝试设置元标记。
<meta name="description" content="text here"/>
这是我尝试过的,但它不起作用也不会导致任何错误。
js.Global().Get("document").Set(`meta[name="description"]`, "new text here")
有什么建议吗?
【问题讨论】:
标签: javascript html webassembly
我正在尝试设置元标记。
<meta name="description" content="text here"/>
这是我尝试过的,但它不起作用也不会导致任何错误。
js.Global().Get("document").Set(`meta[name="description"]`, "new text here")
有什么建议吗?
【问题讨论】:
标签: javascript html webassembly
我认为您当前所做的与 JavaScript 中的 document["meta[name=\"description\"]"] = "new text here" 相同,但它并没有按照您的意愿行事。
你需要的大概是这样的:
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")
【讨论】: