【问题标题】:HTML tags passed within string not rendering fine在字符串中传递的 HTML 标记无法正常呈现
【发布时间】:2017-05-27 05:56:09
【问题描述】:
  • 我是 js 新手,
  • 我的下拉滑块工作正常。
  • 使用 p 标签显示内容正常
  • 但在那个 p 标签内我需要添加另一个链接或列表标签
  • 如果我给它显示整个 a 标签,但它不会像普通网页那样呈现。因为我给了一个字符串。 content={PLAYER.accordion(ballInfo, "qwe

    testing

    "
    )}
  • 你能告诉我如何解决它吗?
  • 在下面提供我的代码
     static accordion(ballInfo, content) {
        if (ballInfo.isRetrieving) {
            return (





 <AccordionHeader className="jump-player-question-title jump-submenu-dropmenuHeader" header="ball ball ball ball sjsdsdkjjksddjks?" content={PLAYER.accordion(ballInfo, "qwe <p> testing</p>")} />

 <AccordionHeader className="jump-player-question-title jump-submenu-dropmenuHeader" header="dsknjdsncjdnsjkcsdnjcsdncjkdsn" content={PLAYER.accordion(ballInfo, "asd <a href="#">testing 2</a>")} />

【问题讨论】:

  • 试试content={PLAYER.accordion(ballInfo, (&lt;div&gt;qwe &lt;p&gt; testing&lt;/p&gt;&lt;/div&gt;))}。手风琴的 content 参数现在应该是有效的 JSX。

标签: javascript jquery html reactjs redux


【解决方案1】:

我不是反应专家,但你可以试试这个,替换

<p> {{content}} </p>

有了这个

<p dangerouslySetInnerHTML={{__html: content}} />

【讨论】:

  • 所以如果我在 p 标签中给出一个标签,它会作为一个链接出现
  • @Xp Uncaught ReferenceError: 标记未在 ACCORDION 的 ACCORDION.render (accordion.jsx:40) 的 Function.renderContent (accordion.jsx:19) 中定义。 (makeAssimilatePrototype.js: 15) 在 ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:587) 在 ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:607) 在 ReactCompositeComponentWrapper.wrapper [as _renderVali
  • @xp 我用谷歌搜索了错误,但没有看到任何解决方案:(
  • @xp:嘿,它起作用了...以前是不是期望标记库??
  • 是的,是的,但在这种情况下没有必要,这是为了其他事情
猜你喜欢
  • 2019-02-28
  • 1970-01-01
  • 2020-03-17
  • 2015-05-23
  • 2016-02-29
  • 1970-01-01
  • 2013-07-23
  • 2020-06-06
  • 2021-02-14
相关资源
最近更新 更多