1. 2015.04.27 jQuery .attr() vs .prop()
  2. 2013.05.24 PHP Closing Tag

jQuery .attr() vs .prop()

jQuery에서 .attr()과 .prop()은 사용시 몇가지 차이점이 있다.


.attr()의 경우 이름 그대로 attribute를 컨트롤 하기위함이고, .prop()의 경우 property를 컨트롤할때 사용한다.


간단한 예를 들어서..


<input type="checkbox" id="check" checked="checked" />
<label for="check">Check Me...</label>
$('#check').change(function() {
    var $input = $(this);
    console.log(".attr('checked'): " + $input.attr('checked'));
    console.log(".prop('checked'): " + $input.prop('checked'));
    console.log(".is('checked'): " + $input.is('checked'));
}).change();


위 체크박스를 클릭시..


.attr()의 경우 체크여부와 상관없이 항상 'checked'만을 리턴하고..

.prop()의 경우 체크여부에 따라 true, false를 리턴한다.


단, jquery 1.6 이전 버전엔 .prop()이 없으니 버전을 확인하고 사용해야한다.

'WebDevelop > jQuery' 카테고리의 다른 글

영역내에서 마우스 휠되도록...  (0) 2016.06.28
jQuery와 prototype의 충돌 해결방법  (0) 2013.05.13
jQuery selector시 좋은 습관  (0) 2009.10.13

PHP Closing Tag

The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.


INCORRECT: 

<?php echo "Here's my code!"; ?> 


CORRECT: 

<?php echo "Here's my code!"; 
/* End of file myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */



** 한국어로 요약**

파일 끝에 스페이스나 엔터가 들어가면 php파일의 output이 생깁니다.

output이 생기면 웹서버에서 헤더를 씌우고 출력을 내보냅니다.


요즘 프로그래밍 방식인 MVC 프로그래밍에서는 (모델, 뷰, 컨트롤러, 핼퍼, 라이브러리 등등)  많은 것을 로드하고 사용해야 합니다.

그런데 실수로 파일에 스페이스바(공백)가 들어가버리면 망하므로 인클루드 될 모듈파일은 되도록 php closing tag는 안쓰는게 좋습니다.


즉 화면에 아무런 출력이 필요없는 파일이면 (곧 소스 전체가 php이면) close tag 를 생략하는 것이 좋습니다.

(아 물론 일반 코딩에서는 닫으셔야 합니다.)

<body>
<?php
echo "hello world!";
?>
</body>


이런 코드를 짜신다면 당연히 닫아야 겠죠?


출처: https://lael.be/171

'WebDevelop > PHP' 카테고리의 다른 글

heredoc syntax  (0) 2008.10.22
Window APM + curl 연동  (0) 2008.06.27
윈도우 APM 환경에서 mail() 함수 사용  (0) 2008.06.15
Return top