我已经添加了一个ID =“ShowAll”的按钮,我想执行一个功能来更改文本框,然后删除标记。当我第一次单击该按钮并且图标成功更改并且标记已成功添加到Google地图时。但是,当我再次点击按钮时。该按钮未更改为原始值,并且未按预期执行代码。任何人都可以帮我看看编码。非常感谢。
var ShowAll=function() {
if (document.getElementById("ShowAll").value = "Show All Trig Station") {
document.getElementById("ShowAll").value="Hide All Trig Station";
//ShowAll.value = "Hide All Trig Station";
var URL2="Show_all_trig.php";
$.ajax({
url: URL2,
// data: $('#sendForm').serialize(),
type: "POST",
dataType: "json",
success: function(data){
$.each(data, function(i, item) {
station_num = item.station_num;
trig_name = item.trig_name;
loc_lat = item.loc_lat;
loc_long = item.loc_long;
loc = new google.maps.LatLng(loc_lat, loc_long);
var trigicon = 'images/Start2.png';
marker = new google.maps.Marker({
map: map,
position: loc,
icon: trigicon,
title: trig_name
})
markersArray.push(marker)
//html = "<b>Trig. Station Name: </b>" + trig_name + "<br/> <b>Station Number: </b>" + station_num + "<br/> <a target='_blank' href= 'summarysheet/"+ station_num +".pdf'>Trig. Station Summary</a>";
html = "<b>Trig. Station Name: </b>" + trig_name + "<br/> <b>Station Number: </b>" + station_num + "<br/> <a target='_blank' href= 'http://www.geodetic.gov.hk/summarysheet/"+ station_num +".pdf'>Trig. Station Summary</a>";
(function(temp_html,temp_map,temp_marker) {
google.maps.event.addListener(temp_marker, 'click', function() {
infoWindow.setContent(temp_html);
infoWindow.open(temp_map, temp_marker);
});
}(html,map,marker));
});
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
} else {
document.getElementById("ShowAll").value="Show All Trig Station";
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
};
<table>
<h4>Building Name, Facilities Name and Address Search</h4>
<tr>
<td><input type="text" size="40" id="address" value="Find building, facilities, address..." onclick="if(this.value=='Find building, facilities, address...'){this.value=''}" onblur="if(this.value==''){this.value='Find building, facilities, address...'}"></td>
<td><input type="button" value="Geocode" onclick="codeAddress()"></td>
</tr>
</table>
答案 0 :(得分:0)
你在这里弄错了
if (document.getElementById("ShowAll").value = "Show All Trig Station") {
检查 = 符号..:)