gpt4 book ai didi

javascript - toUpperCase() 在 React Native 中不起作用,它重复第一个字母两次

转载 作者:行者123 更新时间:2023-11-28 03:06:50 24 4
gpt4 key购买 nike

这是我的代码,有 3 个输入字段,在 uniqueIdNo 中,每当我必须输入时,它应该自动转换为大写。我正在使用 toUpperCase() 函数,它也转换为大写,但是如果我写 ab 两个字母,那么接下来的 AAB 意味着无论我输入的第一个字母是什么,它都会加上它并出现两次。

this.state={
firstName: props.firstName || '',
lastName: props.lastName || '',
uniqueIdNo:props.uniqueIdNo || '',
}
onChangeText = async (text, identifier) => {
if (identifier === "FN") {
this.setState({
firstName: text
});
} else if (identifier === "LN") {
this.setState({
lastName: text
});
} else if (identifier === "UIN") {
this.setState({
uniqueIdNo: text.toUpperCase()
});
}
};
<Item style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
<Input
value={firstName}
keyboardType="default"
onChangeText={text => this.onChangeText(text, "FN")}
/>
</Item>
<Item style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
<Input
value={lastName}
keyboardType="default"
onChangeText={text => this.onChangeText(text, "LN")}
/>
</Item>
<Item style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
<Input
value={uniqueIdNo}
onChangeText={text => this.onChangeText(text, "UIN")}
/>
</Item>

最佳答案

您可以使用 KeyboardType 属性,在 Android 中您可以将键盘类型设置为 visible-password 和 iOS default

 keyboardType={Platform.OS === 'ios' ? 'default' : 'visible-password'}

关于javascript - toUpperCase() 在 React Native 中不起作用,它重复第一个字母两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60538406/

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