Ruby智能变量

时间:2018-12-27 23:31:07

标签: ruby

我喜欢看变量的值,所以我写

document.querySelector('#city').addEventListener(click,'keyup', function(e) {
  if (e.keyCode === 13) {

        var city = $(this).val();
        if (city !== '') {

            $.ajax({

                url: 'http://api.openweathermap.org/data/2.5/weather?q=' + city + "&units=metric" +
                    "&APPID=bb037310921af67f24ba53f2bad48b1d",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    var widget = show(data);

                    $("#show").html(widget);

                    $("#city").val(' ');

                }

            });

        } else {
            $("#error").html("<div class='alert alert-danger text-center'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>Field cannot be empty</div>");
        }

    };
});


function show(data) {
    return "<h2>Current Weather for " + data.name + "," + data.sys.country + "</h2>" +
    "<h3><strong>Wind Speed</strong>: " + data.dt + "</h3>" +
        "<h3><strong>Weather</strong>: <img src='http://openweathermap.org/img/w/" + data.weather[0].icon + ".png'>" + data.weather[0].main + "</h3>" +
        "<h3><strong>Description</strong>: " + data.weather[0].description + "</h3>" +
        "<h3><strong>Temperature</strong>: " + data.main.temp + "&deg;C</h3>" +
        "<h3><strong>Wind Direction</strong>: " + data.wind.deg + "&deg;</h3>";

}

有没有办法说

<body>
    <div class="jumbotron" id="jumbo">
        <h2 class="text-center" id="th2">Weather</h2>
    </div>

    <div class="container" id="cont">
        <div class="row">
            <h2 class="text-center text-primary">Your City</h2>
            <span id="error"></span>
        </div>

        <div class="row form-group form-inline" id="rowDiv">
            <input type="text" name="city" id="city" class="form-control" placeholder="City Name">
            <button id="submitWeather" class="btn btn-primary">Search City</button>
        </div>

        <div id="show"></div>

        </div>

或其他方法名称,并获得输出

puts "count=#{@count}"

0 个答案:

没有答案