0

我已经添加了一个 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>
4

1 回答 1

0

你在这里犯了错误

if (document.getElementById("ShowAll").value = "Show All Trig Station") {

检查=符号 .. :)

于 2013-05-11T17:16:08.087 回答