gpt4 book ai didi

javascript - 如何获取组件中的material ui pickers值?

转载 作者:行者123 更新时间:2023-12-01 01:58:09 25 4
gpt4 key购买 nike

从日期选择器中选择日期时如何获取组件中的值

演示链接:https://material-ui.com/demos/pickers/

第一个例子

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';

const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 200,
},
});

function DatePickers(props) {
const { classes } = props;

return (
<form className={classes.container} noValidate>
<TextField
id="date"
label="Birthday"
type="date"
defaultValue="2017-05-24"
className={classes.textField}
InputLabelProps={{
shrink: true,
}}
/>
</form>
);
}

DatePickers.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(DatePickers);

提前致谢

最佳答案

从这里引用 API 文档:https://material-ui.com/api/text-field/

export default class App extends PureComponent {
state = {
value: ""
};

render() {
const { value } = this.state;

return (
<div>
<TextField
id="date"
label="Birthday"
type="date"
defaultValue="2017-05-24"
InputLabelProps={{
shrink: true
}}
onChange={event => {
this.setState({ value: event.target.value });
}}
/>
{value}
</div>
);
}
}

以及这里的示例:https://codesandbox.io/s/3rp5zl971

希望这对你有帮助

关于javascript - 如何获取组件中的material ui pickers值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50836567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com