React-键盘事件示例

轻鸟评职场技能2024-05-03 20:32:15  87

import React from "react";import 'bootstrap/dist/css/bootstrap.min.css';const infoMap = { msgInit: '通过键盘在文本框输入字符后在浏览器Console中显示对应的ASCII码', alertInfo: '按回车键,msg值为:',}class KeyBind extends React.Component { constructor(props) { super(props); this.state = { msg: infoMap.msgInit, } } keyUp = (e) => { console.log(e.keyCode); if (e.keyCode === 13) { alert(infoMap.alertInfo + e.target.value); } } render { return (

{infoMap.msgInit}

) }}const KeyboardEventExample = => { return ( )}export default KeyboardEventExample;

按回车键,效果:

转载此文是出于传递更多信息目的。若来源标注错误或侵犯了您的合法权益,请与本站联系,我们将及时更正、删除、谢谢。
https://www.414w.com/read/408028.html
0
最新回复(0)