finalspeed
V2EX  ›  React

一道面试题 React

  •  
  •   finalspeed · Mar 1, 2017 · 7959 views
    This topic created in 3543 days ago, the information mentioned may be changed or developed.

    http://codepen.io/TimJin/pen/wgbPOx

    链接里的代码现在不能输出任何可见信息,请修改 js 代码 使屏幕上可以看到 aoeu 。不能修改#app 节点属性(document.getElementById('app').style.display = "block"; 是无效答案)

    不能修改 html 和 css 代码

    14 replies  •  2018-06-16 14:01:19 +08:00
    blanu
    blanu
    Mar 2, 2017
    1
    非常想知道答案
    raquelken
    raquelken
    Mar 2, 2017
    2
    render 到 body 上不行么?
    czheo
    czheo
    Mar 2, 2017❤️1
    3
    是要这个意思吗?
    componentDidMount() {
    ReactDOM.findDOMNode(this).parentNode.style.display="block"
    }
    markx
    markx
    Mar 2, 2017
    4
    呃要不然直接 document.write('aoeu')?
    murmur
    murmur
    Mar 2, 2017
    5
    直接写一段内联 style disply 是 block!important 不就完了。。没说不准修改节点属性又没说不允许额外 css
    murmur
    murmur
    Mar 2, 2017
    6
    *更正,是创建一个新的 style 节点
    rashawn
    rashawn
    Mar 2, 2017 via iPhone
    7
    让我写我会加个 three.js ……

    不懂 react
    JenJieJu
    JenJieJu
    Mar 2, 2017 via iPhone
    8
    finalspeed
    finalspeed
    OP
    Mar 2, 2017
    9
    感谢各位的回答, 我不懂 React, 也不知道答案, 所以上来问问 V 友,
    @czheo #3, 测试可以显示"aoeu''.
    blanu
    blanu
    Mar 2, 2017 via iPhone
    10
    @finalspeed 晕了,那个也是相当于修改了 dom 节点属性啊…我还以为你知道答案…
    yinfxs
    yinfxs
    Jun 16, 2018
    11
    class Application extends React.Component {
    render(){
    return this.props.children;
    }
    }

    //DO NOT MAKE CHANGES BELOW THIS LINE
    ReactDOM.render(<Application><div>aoeu</div></Application>, document.body);
    yinfxs
    yinfxs
    Jun 16, 2018
    12
    看漏了,请忽略我的回复
    yinfxs
    yinfxs
    Jun 16, 2018
    13
    class Application extends React.Component {
    componentDidMount() {
    const _ = ReactDOM.findDOMNode(this);
    _.parentNode.parentNode.append(_)
    }
    render(){
    return this.props.children;
    }
    }

    //DO NOT MAKE CHANGES BELOW THIS LINE
    ReactDOM.render(<Application><div>aoeu</div></Application>, document.getElementById('app'));
    yinfxs
    yinfxs
    Jun 16, 2018
    14
    这样不知道是不是标准答案,但是满足你说的要求:
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2963 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 65ms · UTC 00:46 · PVG 08:46 · LAX 16:46 · JFK 19:46
    ♥ Do have faith in what you're doing.