- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是来自 https://developer.forecast.io/docs/v2 的一个很好的例子
我想做的和尝试的是:
我有一个简单的网页,我想在其中显示当前预报和扩展预报。
这是我的 Index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html lang="en" class="no-js" ng-app="myApp">
<head>
<title>Weather Forecaster</title>
<meta charset="UTF-8">
<!-- favicon -->
<link rel="shortcut icon" href="images/Oxygen-Icons.org-Oxygen-Status-weather-clear.ico" />
<!-- END favicon -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<link href="css/jquery.jdigiclock.css" rel="stylesheet" type="text/css" />
<link href="css/wx-custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-1.12.2.js"></script>
</head>
<body ng-controller="wxController as ctrlWx">
<div class="container">
<div class="row">
<div class="col-10">
<div id="my-div" ng-model="myiFrame">
<iframe src="http://www.latlong.net/convert-address-to-lat-long.html" id="my-iframe" scrolling="no"></iframe>
</div>
<div id="plugin_container" class="forecast-panel">
<h1>Here's Today's Weather</h1>
<div class="fc forecast-panel1">
<p class="dayTitle">Day 1</p>
</div>
<div class="spacer"></div>
<div class="fc forecast-panel2">
<p class="dayTitle">Day 2</p>
</div>
<div class="spacer"></div>
<div class="fc forecast-panel3">
<p class="dayTitle">Day 3</p>
</div>
<div class="spacer"></div>
<div class="fc forecast-panel4">
<p class="dayTitle">Day 4</p>
</div>
<div class="spacer"></div>
<div class="fc forecast-panel5">
<p class="dayTitle">Day 5</p>
</div>
</div>
</div>
</div>
</div>
<script src="js/angular/angular.min.js" type="text/javascript"></script>
<script src="js/angular/app.js" type="text/javascript"></script>
<script src="js/angular/controller.js" type="text/javascript"></script>
<script src="js/angular/services.js" type="text/javascript"></script>
<script src="js/angular/ang-custom.js" type="text/javascript"></script>
</body>
</html>
注意“IFRAME”...... src 是这样的:http://www.latlong.net/convert-address-to-lat-long.html
现在,如果你去那里,这很酷,你可以输入任何地址来获取该地址的 LAT LON:
这是一个屏幕截图,其中包含华盛顿特区的 LAT LON 示例......白宫。
好的,现在,我的代码使用带有简单 Controller 和服务的 Angular...
这里:
应用程序:
/* global angular */
// Code goes here
var myApp;
myApp = angular.module("myApp", []);
myApp.config(function ($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist(['self', '**']);
});
console.log("Host name is: " + document.location.hostname);
//if (document.location.hostname === "localhost") {
// myApp.constant('URL', '/WeatherForecaster/js/json/');
//} else if (document.location.hostname === "omnimanger.co/wx" || "www.omnimanager.co/wx") {
// myApp.constant('URL', '/js/json/');
//} else {
// myApp.constant('URL', '/wx/js/json/');
//}
myApp.constant("URL", {
//Default LAT/LON for CONCRETE
apiKey: "3bb0f0fe93c92922f0b42f9eabda48d0/",
lat: "48.530031",
lon: ",-121.879460",
country: "us",
uri: "https://api.forecast.io/forecast/"
}).config(function($httpProvider){
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});;
myApp.constant("wx", {
data: {
latitude: 0,
longitude: 0,
currently: {},
minutely: {
summary: "",
icon: "",
data: []
},
hourly: {
summary: "",
icon: "",
data: []
},
daily: {
summary: "",
icon: "",
data: []
},
flags: {
sources: [],
"lamp-stations": [],
"isd-stations": [],
"madis-stations": [],
units: ""
}
}
});
Controller :
'use strict';
myApp.controller('wxController', function (wxDataService) {
var ctrlWx = this;
//Listen for the Submit (FIND) button on the iFrame
ctrlWx.content = {};
console.log("LAT/LON: ", ctrlWx.latlon);
ctrlWx.fetchWx = function () {
//General Data
wxDataService.getWxData().then(function (result) {
ctrlWx.content = result;
console.log("All Data: ", result);
});
};
ctrlWx.fetchWx();
});
服务:
myApp.factory('wxDataService', function ($http, URL) {
console.log("URL", URL);
//DEFAULT Headers for KEY and AUTH TOKEN
var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': ['GET', 'POST'],
'Access-Control-Allow-Headers': 'Content-Type',
'Content-Type': 'application/json'
};
var myURL = {
data: {
header: headers,
uri: URL.uri + URL.apiKey + URL.lat + URL.lon
}
};
var getWxData = function () {
return $http.get(myURL)
.success(function (data) {
console.log("SUCCESS!");
console.log("The Weather Data is here: " + data);
return data;
})
.error(function (e) {
console.log("He\'s dead Jim!<br>", e);
return e;
});
};
return {
getWxData: getWxData
};
});
我正在努力实现的解决方案:
当用户输入地址并单击生成 LAT LON 的“查找”按钮时,我想在 IFRAME 中捕获该 LAT LON。
这就是我想要做的,但我知道我需要制定一个指令,将“CLICK”或“SUBMIT”事件绑定(bind)到 FIND 按钮。我下面的不是那个;还没有。
var latlon = {};
$(function () {
$('#my-iframe').load(function () {
$(this).contents().find("#latlongform, #gadres").live('blur', function (e) {
latlon = {
mylat: $("input[name='lat']").val(),
mylon: $("input[name='lon']").val()
};
if (e) {
console.log("Err: ", e);
return e;
}
});
});
});
吉文斯:
FORM和LAT LON如下:
<div class="row">
<div class="col-8 graybox">
<form id="latlongform">
<label for="gadres">Address</label>
<input id="gadres" type="text" class="width70" placeholder="Type address here to get lat long" required="">
<button title="Find lat long coordinates" class="button">Find</button><br>
<small>Write city name with country code for better results.</small>
</form>
<div class="row">
<div class="col-6 m2">
<label for="lat">Latitude</label>
<input type="text" name="lat" id="lat" placeholder="lat coordinate">
</div>
<div class="col-6 m2">
<label for="lng">Longitude</label>
<input type="text" name="lng" id="lng" placeholder="long coordinate">
</div>
</div>
</div>
</div>
问题:
我怎样才能得到 LAT LON,“在”用户单击“查找”之后,然后启动我的 Angular 服务以将 CALL 注入(inject)到获取天气数据的 URL 中……如前所述。这是天气数据 JSON 对象。它使用一个 API key ,我的 key 每天只能使用 1000 次。
如果您想查看天气 API 的结果,您需要获得一个免费的 API_KEY....它每天提供 1000 次点击...
谢谢大家,我希望你能回答这一切这是一个有效的问题。
最佳答案
forecast.io
网站不支持 GET 操作的 CORS(跨源资源共享),但它支持 JSONP。
var url = myURL.data.uri;
var jsonpURL = url+"?callback=JSON_CALLBACK";
var getWxData = function () {
return $http.jsonp(jsonpURL)
.then(function (response) {
console.log("SUCCESS!");
console.log(response.data);
//return to chain data
return response.data;
})
.catch(function (e) {
console.log("He\'s dead Jim!");
console.log(e);
//throw to chain rejection
throw e;
});
};
LAT: 48.530031
LOG: -121.87946
TIMEZONE: America/Los_Angeles
SUMMARY: Partly Cloudy
TEMP: 56.02
请注意,我将 .success
和 .error
方法分别更改为 .then
和 .catch
。那些旧方法是 deprecated并忽略返回值。
关于javascript - 单击 "Submit"按钮获取值时访问元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36375523/
我创建了一个函数来在两个元素的 style.display 之间切换为“none”或“block”。我在这里遇到的问题是“发送”按钮似乎与“切换”按钮具有相同的行为。这不是我指定它要做的事情。我想知道
当我使用 validate.js 添加表单验证时,其验证正常并显示验证消息。但输入 type="submit"值在操作页面结构中显示两次。 为了说明,我有两个 .cfm 文件,index.cfm 具有
我有一个 s:form,里面有 sj:submit 和 s:submit,sj:submit 工作正常,但 s:submit 按钮不起作用。当我点击 s:submit 按钮时没有任何反应。 我尝试在表
参见http://jsfiddle.net/8KNc7/5/有关我正在讨论的内容的工作示例(目前在 Firefox 15 中进行测试,尚未尝试其他版本)。 我有一个带有 submit 输入和 butt
我有一个包含表单的 HTML 页面。我想做一些字段 "required" 。问题是我没有使用 在我的表单中,我使用 Javascript 函数来提交表单,因为我需要将 Javascript 变量发送到
如果用户提交表单,我想运行特定的 PHP block 。如果我使用带有 name="submit"的提交按钮并且: 我对 javascript 一无所知,我希望代码在用户更改下拉菜单时运行。如果我将
我有一个网站 www.abc.com,其中有一个页面 xyz.php。 xyz.php 采用表单提交事件读取数据并保存在数据库中。 www.abc.com 有一个针对 xyz.php 执行操作的表单。
这个问题在这里已经有了答案: JavaScript post request like a form submit (32 个答案) 关闭 9 年前。 我查看了不同的线程,但找不到合适的解决方案。
我有一个表单提交触发器和一个确认引导框,它显示在单击表单提交按钮上。在 bootbox 中确认如果用户同意我提交表单。我的问题是 onsubmit 在用户说是之前触发,并且当我在 bootbox 中调
我正在使用 JavaScript .submit() 函数提交我的表单。 form.submit(); 但是当我使用 addEventListener 来捕获我的提交事件时,它不起作用。 form.a
编辑:在考虑回答问题之前,请仔细阅读问题的所有内容。我既不是在生产代码中使用内联事件处理程序的可取性,也不是在实现我所引用的文章所 promise 的结果的最佳方法。这是关于Javascript语义和
这是我的形式,对我来说看起来不错。在这种形式中,我放置了这个按钮: 这是它调用的函数: function confirmSubmit() { // get the number of st
以下哪个 CSS 选择器更快? input[type="submit"] { /* styles */ } 或 [type="submit"] { /* styles */ } 只是好
在表单上添加提交按钮的符合标准的正确语义方式是什么?我不需要按钮中的图像或背景,只需要简单的文本,也许是带弯 Angular 的渐变背景(使用 CSS3)。这些是我所知道的方法: click her
我的 App.js 包含以下代码: var app = angular.module('githubApp', []); 我有 githubAppController 和以下代码: app.contr
jQuery 允许通过以下任一方式以编程方式触发表单提交: $('.js-form-class-hook').submit(); $('.js-form-class-hook').trigger('s
我有一个表单,其中一个按钮使用 onClick 事件提交。 " 此外,我有一个输入,当输入处于焦点状态时按下回车键时会触发 couponButton。 虽然它们都触发相同的事件 (.submit()
目前只是尝试实现这些按钮:http://web.archive.org/web/20110721191046/http://particletree.com/features/rediscoverin
我正在提交我的第一个构建以供 TestFlight beta 审查,在创建一个组后,添加 4 名团队成员添加我的构建,取消单击该框以表示我需要登录信息来测试该应用程序,我单击“提交”审查。” iTun
我有一个带有 onsubmit 属性的表单。我需要绑定(bind)一个新的提交事件,并且我需要在任何现有提交函数之前执行此事件。 下面的代码演示了这个问题。 Test
我是一名优秀的程序员,十分优秀!