需要检查三个条件并根据条件为变量赋值。
if(a =="z1"){
b = "one";
} else if(a =="z2"){
b = "two";
} else if(a =="z3"){
b = "three";
}
Run Code Online (Sandbox Code Playgroud)
是否可以在 JavaScript 中使用 来做到这一点?: 语句使其成为单行代码
我试图在谷歌地图上覆盖不同州的美国地图。我知道我可以使用loadGeoJson谷歌地图的功能,但我想为不同的状态着色。
这是我正在尝试的代码。我在粘贴代码时删除了 API 密钥。
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.stations, .stations svg {
position: absolute;
}
.stations svg {
width: 60px;
height: 20px;
padding-right: 100px;
font: 10px sans-serif;
}
.stations circle {
fill: brown;
stroke: black;
stroke-width: 1.5px;
}
</style>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key="></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// Create the Google Map…
d3.json("https://raw.githubusercontent.com/alignedleft/d3-book/master/chapter_12/us-states.json", function(json) {
var map = new google.maps.Map(d3.select("#map").node(), { …Run Code Online (Sandbox Code Playgroud)