【问题标题】:Wemassembly set meta tagWemassembly 设置元标记
【发布时间】: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


    【解决方案1】:

    我认为您当前所做的与 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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-18
      • 2015-09-03
      • 2013-01-27
      • 1970-01-01
      • 2012-09-15
      • 2016-04-04
      • 1970-01-01
      • 2014-03-27
      相关资源
      最近更新 更多