1
我有,我想格式化的onblur输入字段值,这里是我的代码如下所示:如何在React中触发Blur事件?
组件:
<Input
onBlur={this.formatEndpoint}
/>
功能:
formatEndpoint() {
let endpoint = this.state.inputEndpoint;
endpoint = endpoint.replace(/\s/g, '').replace(/\/+$/, '');
if (endpoint.slice(-1) === '/') {
endpoint = endpoint.substring(0, endpoint.length - 1);
}
console.log('anything');
}
为什么甚至没有console.log()
工作在Blur上?谢谢。
看起来像一个自定义的'输入'。你应该检查组件是否支持'onBlur'。 – Panther
是的,Input的定义是什么样的?你写了吗? – mikkelrd
这些评论有帮助,我只需要添加一个onBlur道具到'Input'。 –