gpt4 book ai didi

javascript - 如何触发TouchableOpacity的onPress事件?

转载 作者:行者123 更新时间:2023-12-02 04:33:30 24 4
gpt4 key购买 nike

在 html 中使用 jQuery:

$("input:button").on("click",function(){alert(1)}).click()

可以触发点击事件。

我想在 react-native 中对 TouchableOpacityonPress 事件做类似的事情。

<TouchableOpacity activeOpacity={0.75} key={id} onPress={() => {onChangeAttribute(key)}}>
{<Text>{value.name}</Text>}
</TouchableOpacity>

我不知道该怎么做。我用谷歌搜索但一无所获。我只想在代码中触发 onPress 事件,而不是通过用户点击。

提前致谢。

最佳答案

你的代码应该是这样的:

render () {
<TouchableOpacity activeOpacity={0.75} key={id} onPress={onChangeAttribute(key)}>
{ <Text>{value.name}</Text> }
</TouchableOpacity>
}

关于javascript - 如何触发TouchableOpacity的onPress事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46297011/

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