2012-05-09 2 views
4

외부 스크립트를 호출하는 스크립트 태그에 주석을 삽입하면 어떤 문제가 발생할 수 있습니까? 나의 동료는 이것이 좋은 습관이 아니라고 말했다. 이 같은스크립트 링크 태그의 주석 사용

뭔가 : 잘못된

<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"> 
      // import jQuery 
      // cdn refers to a remotely hosted library 
</script> 

답변

1

어쩌면 당신의 동료는이

<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"> 
      // import jQuery 
      // cdn refers to a remotely hosted library 
</script> 

을하는 습관을거야 우려하고 그리고 결국이 작동하지 않는 이유를 알아 내기 위해 투쟁

<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"> 
    $(document).ready(function() { 
      $('#ActionButton').click(DoAction); 
    }); 
</script> 

나쁜 습관을 개발했기 때문에

3

아무것도, 어쩌면 가독성. 또한 소스에서 내용을 덮어 씁니다.

<!-- import jQuery. CDN refers to a remotely hosted library --> 
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script> 
3

전혀 문제가 없습니다. script 요소에 src 특성이 있으면 콘텐츠가 무시됩니다.

JavaScript를 지원하지 않는 고대 브라우저에서 사용되는 스크립트 태그 내부의 HTML 주석을 동료가 언급했을 수도 있습니다.

<script> 
    <!-- 
     // JS was here 
    // --> 
</script> 

Are HTML comments inside script tags a best practice?

관련 문제