您好,JSON 新手,我想知道是否可以从此 API 的 JSON 结果中调用“国家/地区”:http://maps.google.com/maps/api/js ?sensor=true&libraries=places
我尝试使用一个循环来获取 JSON 结果的最后一部分地址组件,但我意识到“国家/地区”的位置因用户的输入而异
详细说明:
场景 1:用户输入:
736 Lockhart Court, Harristown QLD 4350, Australia
结果:
澳大利亚//这是正确的
场景 2:用户输入:
美国弗吉尼亚州汉普顿兰利空军基地
结果:
弗吉尼亚//不正确
我当前的代码获取数组 address_components 的最后一个索引,我想知道我是否可以做这样的事情*data.results[0].address_components[country].long_name;*,但我只是不知道正确的方法。
代码:
<html>
<head></head>
<title></title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=places"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#btn1 ").click(function() {
var address=encodeURI($('#userInput').val());
var url='https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&sensor=true';
$.getJSON(url, function(data){
for(var row=0; row<data.results.length;row++){
document.getElementById('res').value = (data.results[row].address_components[data.results[row].address_components.length-2].long_name);
}
});
});
});
</script>
<body>
<input type="text" id="res">
<input type="text" name="userInput" id="userInput" />
<input type="button" id="btn1" value="Load Data" …Run Code Online (Sandbox Code Playgroud) cakephp的新功能遇到了我必须将文本和图像作为链接的场景.幸运的是它是成功的,但是我注意到我的链接上有一个下划线,我必须删除它,你可以在下面的图片上看到+关于我是如何做到这样的代码:
Cakephp代码:
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express    '),
'http://example.com', array('escape' => false));
Run Code Online (Sandbox Code Playgroud)
通常只需添加以下内容即可:
style="text-decoration:none"
Run Code Online (Sandbox Code Playgroud)
在css中,但是因为我是蛋糕的新手,所以我不知道如何设置我可以用于css的id或类的语法,或者我喜欢的语法,直接添加style ="text-decoration :无"在阵列中.我试过这个,但它不起作用.
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express    '),
'http://example.com', array('escape' => false,'style'=>'text-decoration:none'));
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?任何帮助表示赞赏