>  기사  >  백엔드 개발  >  javascript - 질문이 있습니다. 외부 js 파일이 다운로드되지 않아 Ready 함수가 실행되지 않아서 그런가요?

javascript - 질문이 있습니다. 외부 js 파일이 다운로드되지 않아 Ready 함수가 실행되지 않아서 그런가요?

WBOY
WBOY원래의
2016-12-01 00:56:451160검색

최근 웹사이트에서 Google의 지도 API를 인용하는 문제가 발생했는데, 해당 js를 오랫동안 참조해야 했고 항상 보류 상태였습니다. 버튼, 특히 이 버튼은 클릭 이벤트가 준비 기능에 있는 경우 아무런 효과가 없습니다. 해결책은 무엇입니까?

<code>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?language=<?php echo $language; ?>"></script> 
   
 <script type="text/javascript"> 


  $(document).ready(function() {
    var lat = {lat: <?php echo $geocodes[0]; ?>, lng: <?php echo $geocodes[1]; ?>}; 
    var myOptions = {  
       zoom: 17,
       center: lat,
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       disableDefaultUI: true,
       zoomControl: true,
    }; 
    var map = new google.maps.Map(document.getElementById("map"), myOptions);   
    var marker = new google.maps.Marker({
      map: map,
      // Define the place with a location, and a query string.
      place: {
        location: lat,
        query: `<?php echo $address; ?>`

      },
      // Attributions help users find your site again.
      attribution: {
        source: 'Google Maps JavaScript API',
        webUrl: 'https://developers.google.com/maps/'
      }
    });

    // Construct a new InfoWindow.
    var infoWindow = new google.maps.InfoWindow({
      content: `<?php echo $store; ?><br><?php echo $address; ?>`
    });
      infoWindow.open(map, marker);
    // Opens the InfoWindow when marker is clicked.
    marker.addListener('click', function() {
      infoWindow.open(map, marker);
    }); 

  });
    
 </script> </code>

기타 준비된 기능

<code>$(document).ready(function() {
    // Language
    $('.language a').on('click', function(e) {
        e.preventDefault();

        $('.language input[name=\'code\']').attr('value', $(this).attr('href'));

        $('.language').submit();
    });
});</code>

답글 내용:

최근 웹사이트에서 Google의 지도 API를 인용하는 문제가 발생했는데, 해당 js를 오랫동안 참조해야 했고 항상 보류 상태였습니다. 버튼, 특히 이 버튼은 클릭 이벤트가 준비 기능에 있는 경우 아무런 효과가 없습니다. 해결책은 무엇입니까?

<code>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?language=<?php echo $language; ?>"></script> 
   
 <script type="text/javascript"> 


  $(document).ready(function() {
    var lat = {lat: <?php echo $geocodes[0]; ?>, lng: <?php echo $geocodes[1]; ?>}; 
    var myOptions = {  
       zoom: 17,
       center: lat,
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       disableDefaultUI: true,
       zoomControl: true,
    }; 
    var map = new google.maps.Map(document.getElementById("map"), myOptions);   
    var marker = new google.maps.Marker({
      map: map,
      // Define the place with a location, and a query string.
      place: {
        location: lat,
        query: `<?php echo $address; ?>`

      },
      // Attributions help users find your site again.
      attribution: {
        source: 'Google Maps JavaScript API',
        webUrl: 'https://developers.google.com/maps/'
      }
    });

    // Construct a new InfoWindow.
    var infoWindow = new google.maps.InfoWindow({
      content: `<?php echo $store; ?><br><?php echo $address; ?>`
    });
      infoWindow.open(map, marker);
    // Opens the InfoWindow when marker is clicked.
    marker.addListener('click', function() {
      infoWindow.open(map, marker);
    }); 

  });
    
 </script> </code>

기타 준비된 기능

<code>$(document).ready(function() {
    // Language
    $('.language a').on('click', function(e) {
        e.preventDefault();

        $('.language input[name=\'code\']').attr('value', $(this).attr('href'));

        $('.language').submit();
    });
});</code>

<code><script>
var js = document.createElement('script');
js.src= 'js地址';
document.querySelector('body').appendChild(js);
</script></code>

차단되지 않습니다

준비된 기능은 Google API에 따라 다르므로 API가 로드될 때까지만 기다릴 수 있습니다. 너무 느린 경우 Google API 파일을 다운로드하여 웹사이트의 정적 리소스에 넣으세요.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.