Top

링크 페이지이동 막기 | Web-Programing
김경훈 (admin) | Editor | 2016/04/14 18:11:20 | 조회:9442

페이지의 링크 클릭시 페이지 이동 막는 방법.



- HTML -

  1. <div class="nolink">
  2. <a href="http://google.com" target="_blank">google</a>
  3. <a href="javascript:location.href='http://naver.com'" target="_blank">google2</a>
  4. <a href="javascript:;" onclick="location.href='http://naver.com'" target="_blank">google3</a>
  5. <button onclick="location.href='http://naver.com'">naver</button>
  6. </div>


- JS -

  1. jQuery(function($){
  2.     var $preview_zone = $('.nolink');
  3.     var msg = 'alert message';
  4.     $preview_zone
  5.       .find('a, [onclick]').on('click', function(){
  6.         alert(msg);
  7.         return false;
  8.       })
  9.       .prop('onclick', null);
  10.     ;
  11. });



 attr과 prop는 비슷한듯 다르다.

 attr은 속성을 문자열로 사용할 때 "checked" 로, prop는 속성을 Boolean으로 사용할 때 true, false 로 사용한다.

  1. // Correct if changing the attribute is desired
  2. $(elem).attr("checked", "checked");
  3. // Correct for checking the checkbox
  4. $(elem).prop("checked", true);
  5. // Correct if removing the attribute is desired
  6. $(elem).removeAttr("checked");
  7. // Correct for clearing the checkbox
  8. $(elem).prop("checked", false);
공유하기
공유하기
0
0
0


댓글을 불러오는 중입니다.
▲ 이전글 아디다스 에이스 존 프로 골키퍼 장갑(AH7804) 김경훈 (admin) 2016-04-15 11:42:45
▼ 다음글 화블 오류 수정 작업과 신규 기능 추가 작업 안내 김경훈 (admin) 2016-04-13 16:13:00