javascript - 从 dom 中隐藏输入值属性

标签 javascript html css reactjs redux

由于某些原因,当 React 更新输入值时,该值显示在 DOM 中。
目前我正在使用这段代码:

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

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

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

非常感谢大家的意见。

最佳答案

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

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"/>

关于javascript - 从 dom 中隐藏输入值属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51562754/

相关文章:

asp.net - jquery UI 对话框和 __DoPostback

javascript - jquery Accordion 自定义点击事件

css - Kendo UI (Graph) 为气泡图上的气泡添加浮雕

css - 在 ExtJS 3 到 4 迁移时保持 CSS 样式

javascript - 当导航栏通过单击关闭时,如果单击此类元素,我如何关闭后续链接或执行按钮?

javascript - Firefox Scratchpad 的 javascript 代码比标准网站 javascript 代码拥有更多权限?

javascript - AngularJS - 需要帮助显示绑定(bind)文本输入中的当前字符串长度

javascript - getComputedTextLength 在 IE10 中抛出错误

html - 网站图标不工作

html - CSS 或 HTML 中的形状