HTML5 天气预报 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

按钮事件

按钮被按下(keypress)事件,if判断按了那个按钮,获取文本框输入值,并调用getWoeid()方法。

$('#city').keypress(function() {
    if (event.which == 13) { // 按下回车键
        selectedCity = $('#city').val();
        getWoeid(selectedCity);
        $('#city').blur();
    }
});

按钮点击事件,改变温度刻度。

$('#btn').click(function() {
        if ($('#btn').html() == "F") {
            unit = "c";
        } else unit = "f";
        $('#btn').html(unit.toUpperCase());
        getWoeid(selectedCity);
    })