[英]Button work on desktop, resized to mobile but dont react on real mobile
i'm learning Api my nearly first thing.我正在学习 Api,这是我的第一件事。 There is a search button that stop working at mobile.有一个在移动设备上停止工作的搜索按钮。 Can't find a reason/ could u have a look?找不到原因/你可以看看吗?
https://codepen.io/DeanWinchester88/pen/ExvxdxX https://codepen.io/DeanWinchester88/pen/ExvxdxX
function showPokemonSearchResult(){
let enteredPokemonName = document.getElementById("pokemonNameByUser").value;
targetPokemon = `https://pokeapi.co/api/v2/pokemon/${enteredPokemonName}`
console.log("target pokemon",targetPokemon)
fetch(targetPokemon)
.then(res => {
if(res){
console.log("Success");
// console.log("res.json",res.json());
return res.json()
}else {
console.log("Failure");
}
})
.then(data =>{
let gotDivForPokemonSearchResult = document.getElementById("divForPokemonSearchResult");
gotDivForPokemonSearchResult.innerHTML = `
<h2> ${data.name}</h2><br>
<img src=${data.sprites["front_default"]}></img>
<img src=${data.sprites["back_default"]}></img>
<p class="text2">Weight: ${data.weight}</p>
<p class="text2">Heigth: ${data.height}</p>
<p class="text2">Base experience: ${data["base_experience"]}</p>
`
console.log(data.id)
})
}
As I can see, pokeapi.co/api/v2/pokemon/
is case sensitive and from mobile the keyboard usually puts the first letter uppercase.如我所见, pokeapi.co/api/v2/pokemon/
区分大小写,从移动设备开始,键盘通常将第一个字母大写。
For example, if your mobile keyboard corrects venusaur with Venusaur the search will fail.例如,如果您的移动键盘使用 Venusaur 更正 venusaur,则搜索将失败。
You might consider adding a .toLowerCase()
when you read the input to avoid this issue at all.您可能会考虑在读取输入时添加.toLowerCase()
以完全避免此问题。
let enteredPokemonName = document.getElementById("pokemonNameByUser").value.toLowerCase();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.