【问题标题】:Hide input value attribute from the dom从dom中隐藏输入值属性
【发布时间】:2019-01-04 20:40:53
【问题描述】:

由于某种原因,当 react 更新输入值时,该值会显示在 DOM 中。
目前我正在使用此代码:

< input type="password" id="password" value="anytext" />

出于安全原因,有什么方法可以隐藏 value 属性中的文本?也许是这样的:

< input type="password" id="password" value />

感谢大家的意见。

【问题讨论】:

标签: javascript html css reactjs redux


【解决方案1】:

在我看来这种行为不会发生:

class Demo extends React.Component {
    constructor(props) {
        super(props);
        this.state = { password: 'test', test: '' }
        setInterval(function() {
            document.getElementById('test').innerText = 'ATTRIBUTE: ' + document.getElementById('password').getAttribute('value');
        }.bind(this), 200);
    }
    render() {
        return <div><input id="password" type="password" value={this.state.password} onChange={(e) => this.setState({password: e.target.value})} /><pre id="test">ATTRIBUTE: {this.state.test}</pre><pre id="value">VALUE: {this.state.password}</pre></div>
    }
}

ReactDOM.render(
  <Demo />,
  document.getElementById("root")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"/>

【讨论】:

猜你喜欢
  • 2017-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-18
  • 2013-11-17
  • 1970-01-01
  • 2011-01-13
相关资源
最近更新 更多