【发布时间】:2019-06-20 06:41:56
【问题描述】:
为什么当我按下回车键时它不运行code,因为我将应该运行的代码放在if statement 中。
当我按enter 它console log 它无法正常运行。
document.getElementById('city-location').addEventListener('keyup', (e) => {
const LOCATION = document.getElementById('city-location').value
if(e.target.which == 13 || e.target.keyCode == 13) {
weatherApi.changeLocation(LOCATION);
storage.setStorage(LOCATION);
getWeatherApi();
} else {
console.log('Wrong key pressed');
}
e.preventDefault();
})
这里是标记:
<form id="weather-modal-form">
<div class="form-group">
<label for="city">City</label>
<input type="text" id="city-location">
</div>
</form>
【问题讨论】:
标签: javascript forms events submit