Jquery 요약tips_jquery
다음은 Jquery 사용 팁 중 일부입니다. 예를 들어, 마우스 오른쪽 버튼 클릭 비활성화, 검색 텍스트 상자 텍스트 숨기기, 새 창에서 링크 열기, 브라우저 감지, 이미지 미리 로드, 페이지 스타일 전환, 모든 열의 높이 동일, 페이지 글꼴 크기 동적으로 제어, 마우스 포인터의 X 값과 Y 값, 요소가 비어 있는지 확인하고, 요소를 교체하고, 지연 로드하고, 요소가 Jquery 컬렉션에 존재하는지 확인하고, DIV를 클릭 가능하게 만들고, 개체를 복제하고, 요소를 가운데에 두고, 개수를 계산합니다. 요소 수, Google 호스트에서 Jquery 클래스 라이브러리 사용, Jquery 비활성화 효과는 Jquery 클래스 라이브러리와 다른 Javascript 클래스 라이브러리 간의 충돌 문제를 해결하는 것입니다.
1. 우클릭 금지
$(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; }); });
2. 검색 텍스트 상자 텍스트 숨기기
검색창을 클릭하면 값이 숨겨집니다.(예는 아래 댓글창에서 확인하실 수 있습니다)
$(document).ready(function() { $("input.text1").val("Enter your search text here"); textFill($('input.text1')); }); function textFill(input){ //input focus text function var originalvalue = input.val(); input.focus( function(){ if( $.trim(input.val()) == originalvalue ){ input.val(''); } }); input.blur( function(){ if( $.trim(input.val()) == '' ){ input.val(originalvalue); } }); }
3.새 창에서 링크 열기
XHTML 1.0 Strict는 코드에서 이 속성을 허용하지 않으므로 이를 사용하여 코드를 유효하게 유지하세요.
$(document).ready(function() { //Example 1: Every link will open in a new window $('a[href^="http://"]').attr("target", "_blank"); //Example 2: Links with the rel="external" attribute will only open in a new window $('a[@rel$='external']').click(function(){ this.target = "_blank"; }); }); // how to use <A href="http://www.opensourcehunter.com" rel=external>open link</A>
4. 브라우저 감지
참고: jQuery 1.4 버전에서는 $.support가 $.browser 변수를 대체했습니다
$(document).ready(function() { // Target Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" ){ // do something } // Target Safari if( $.browser.safari ){ // do something } // Target Chrome if( $.browser.chrome){ // do something } // Target Camino if( $.browser.camino){ // do something } // Target Opera if( $.browser.opera){ // do something } // Target IE6 and below if ($.browser.msie && $.browser.version <= 6 ){ // do something } // Target anything above IE6 if ($.browser.msie && $.browser.version > 6){ // do something } });
5. 이미지 미리 로드
이 코드는 모든 이미지가 로드되는 것을 방지하므로 이미지가 많은 사이트에 유용할 수 있습니다.
$(document).ready(function() { jQuery.preloadImages = function() { for(var i = 0; i<ARGUMENTS.LENGTH; jQuery(?<img { i++)>").attr("src", arguments[i]); } } // how to use $.preloadImages("image1.jpg"); });
6. 페이지 스타일 전환
$(document).ready(function() { $("a.Styleswitcher").click(function() { //swicth the LINK REL attribute with the value in A REL attribute $('link[rel=stylesheet]').attr('href' , $(this).attr('rel')); }); // how to use // place this in your header <LINK rel=stylesheet type=text/css href="default.css"> // the links <A class="Styleswitcher" href="#" rel=default.css>Default Theme</A> <A class="Styleswitcher" href="#" rel=red.css>Red Theme</A> <A class="Styleswitcher" href="#" rel=blue.css>Blue Theme</A> });
7. 높이가 같은 기둥
두 개의 CSS 열을 사용하는 경우 이 방법을 사용하면 두 열의 높이를 동일하게 만들 수 있습니다.
$(document).ready(function() { function equalHeight(group) { tallest = 0; group.each(function() { thisHeight = $(this).height(); if(thisHeight > tallest) { tallest = thisHeight; } }); group.height(tallest); } // how to use $(document).ready(function() { equalHeight($(".left")); equalHeight($(".right")); }); });
8. 페이지 글꼴 크기를 동적으로 제어
사용자는 페이지 글꼴 크기를 변경할 수 있습니다
$(document).ready(function() { // Reset the font size(back to default) var originalFontSize = $('html').css('font-size'); $(".resetFont").click(function(){ $('html').css('font-size', originalFontSize); }); // Increase the font size(bigger font0 $(".increaseFont").click(function(){ var currentFontSize = $('html').css('font-size'); var currentFontSizeNum = parseFloat(currentFontSize, 10); var newFontSize = currentFontSizeNum*1.2; $('html').css('font-size', newFontSize); return false; }); // Decrease the font size(smaller font) $(".decreaseFont").click(function(){ var currentFontSize = $('html').css('font-size'); var currentFontSizeNum = parseFloat(currentFontSize, 10); var newFontSize = currentFontSizeNum*0.8; $('html').css('font-size', newFontSize); return false; }); });
9. 페이지 상단으로 돌아가기
정상(또는 모든 위치)으로 원활하게(애니메이션) 타고 돌아가려면.
$(document).ready(function() { $('a[href*=#]').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']'); if ($target.length) { var targetOffset = $target.offset().top; $('html,body') .animate({scrollTop: targetOffset}, 900); return false; } } }); // how to use // place this where you want to scroll to <A name=top></A> // the link <A href="#top">go to top</A> });
11. 마우스 포인터 XY 값 가져오기
마우스 커서가 어디에 있는지 알고 싶으십니까?
$(document).ready(function() { $().mousemove(function(e){ //display the x and y axis values inside the div with the id XY $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY); }); // how to use <DIV id=XY></DIV> });
12. 요소가 비어 있는지 확인
이를 통해 요소가 비어 있는지 확인할 수 있습니다.
$(document).ready(function() { if ($('#id').html()) { // do something } });
13. 요소 교체
div 또는 다른 것을 교체하고 싶으십니까?
$(document).ready(function() { $('#id').replaceWith(' <DIV>I have been replaced</DIV> '); });
14. jQuery 지연 로딩 기능
뭔가 미루고 싶으신가요?
$(document).ready(function() { window.setTimeout(function() { // do something }, 1000); });
15. 단어 기능 제거
특정 단어를 제거하고 싶으십니까?
$(document).ready(function() { var el = $('#id'); el.html(el.html().replace(/word/ig, "")); });
16. jquery 객체 컬렉션에 해당 요소가 있는지 확인하세요
요소가 존재하는 경우 .length 속성으로 간단히 테스트하세요.
$(document).ready(function() { if ($('#id').length) { // do something } });
17. 전체 DIV를 클릭 가능하게 만듭니다
전체 div를 클릭 가능하게 만들고 싶으십니까?
$(document).ready(function() { $("div").click(function(){ //get the url from href attribute and launch the url window.location=$(this).find("a").attr("href"); return false; }); // how to use <DIV><A href="index.html">home</A></DIV> });
18. ID와 클래스의 변환
Window 크기 변경시 ID와 Class 전환
$(document).ready(function() { function checkWindowSize() { if ( $(window).width() > 1200 ) { $('body').addClass('large'); } else { $('body').removeClass('large'); } } $(window).resize(checkWindowSize); });
19. 객체 복제
div 또는 다른 요소를 복제하세요.
$(document).ready(function() { var cloned = $('#id').clone(); // how to use <DIV id=id></DIV> });
20. 요소를 화면 중앙에 배치하세요
화면 중앙에 요소를 배치하세요.
$(document).ready(function() { jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this; } $("#id").center(); });
21. 자신만의 선택기를 작성하세요
자신만의 선택기를 작성하세요.
$(document).ready(function() { $.extend($.expr[':'], { moreThen1000px: function(a) { return $(a).width() > 1000; } }); $('.box:moreThen1000px').click(function() { // creating a simple js alert box alert('The element that you have clicked is over 1000 pixels wide'); }); });
22. 요소 수를 세어보세요
요소 수를 계산합니다.
$(document).ready(function() { $("p").size(); });
23. 나만의 글머리 기호를 사용하세요
표준 또는 이미지 글머리 기호 대신 자신만의 글머리 기호를 사용하고 싶으신가요?
$(document).ready(function() { $("ul").addClass("Replaced"); $("ul > li").prepend("‒ "); // how to use ul.Replaced { list-style : none; } });
24. Google 호스트에서 Jquery 클래스 라이브러리를 참조하세요
Google에서 jQuery 스크립트를 호스팅하도록 하세요. 이는 두 가지 방법으로 수행할 수 있습니다.
[코드]//예제 1
http://www.google.com/jsapi">>
http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"> 스크립트>
// 예시 2:(가장 좋고 가장 빠른 방법)
[/code">http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">[/code ]
25. Jquery(애니메이션) 효과 비활성화
모든 jQuery 효과 비활성화
$(document).ready(function() { jQuery.fx.off = true; });
26. 다른 자바스크립트 라이브러리와의 충돌
웹사이트의 다른 라이브러리와의 충돌을 방지하려면 이 jQuery 메서드를 사용하고 달러 기호 대신 다른 변수 이름을 할당할 수 있습니다.
$(document).ready(function() { var $jq = jQuery.noConflict(); $jq('#id').show(); });

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











JavaScript 문자열 교체 방법 및 FAQ에 대한 자세한 설명 이 기사는 JavaScript에서 문자열 문자를 대체하는 두 가지 방법 인 내부 JavaScript 코드와 웹 페이지의 내부 HTML을 탐색합니다. JavaScript 코드 내부의 문자열을 교체하십시오 가장 직접적인 방법은 대체 () 메소드를 사용하는 것입니다. str = str.replace ( "find", "replace"); 이 메소드는 첫 번째 일치 만 대체합니다. 모든 경기를 교체하려면 정규 표현식을 사용하고 전역 플래그 g를 추가하십시오. str = str.replace (/fi

이 튜토리얼은 사용자 정의 Google 검색 API를 블로그 또는 웹 사이트에 통합하는 방법을 보여 주며 표준 WordPress 테마 검색 기능보다보다 세련된 검색 경험을 제공합니다. 놀랍게도 쉽습니다! 검색을 Y로 제한 할 수 있습니다

그래서 여기 당신은 Ajax라는이 일에 대해 배울 준비가되어 있습니다. 그러나 정확히 무엇입니까? Ajax라는 용어는 역동적이고 대화식 웹 컨텐츠를 만드는 데 사용되는 느슨한 기술 그룹을 나타냅니다. 원래 Jesse J에 의해 만들어진 Ajax라는 용어

이 기사 시리즈는 2017 년 중반에 최신 정보와 새로운 예제로 다시 작성되었습니다. 이 JSON 예에서는 JSON 형식을 사용하여 파일에 간단한 값을 저장하는 방법을 살펴 봅니다. 키 값 쌍 표기법을 사용하여 모든 종류를 저장할 수 있습니다.

손쉬운 웹 페이지 레이아웃에 대한 jQuery 활용 : 8 에센셜 플러그인 jQuery는 웹 페이지 레이아웃을 크게 단순화합니다. 이 기사는 프로세스를 간소화하는 8 개의 강력한 JQuery 플러그인을 강조합니다. 특히 수동 웹 사이트 생성에 유용합니다.

핵심 포인트 JavaScript에서는 일반적으로 메소드를 "소유"하는 객체를 말하지만 함수가 호출되는 방식에 따라 다릅니다. 현재 객체가 없으면 글로벌 객체를 나타냅니다. 웹 브라우저에서는 창으로 표시됩니다. 함수를 호출 할 때 이것은 전역 객체를 유지하지만 객체 생성자 또는 그 메소드를 호출 할 때는 객체의 인스턴스를 나타냅니다. call (), apply () 및 bind ()와 같은 메소드를 사용 하여이 컨텍스트를 변경할 수 있습니다. 이 방법은 주어진이 값과 매개 변수를 사용하여 함수를 호출합니다. JavaScript는 훌륭한 프로그래밍 언어입니다. 몇 년 전,이 문장은있었습니다

JQuery는 훌륭한 JavaScript 프레임 워크입니다. 그러나 어떤 도서관과 마찬가지로, 때로는 진행 상황을 발견하기 위해 후드 아래로 들어가야합니다. 아마도 버그를 추적하거나 jQuery가 특정 UI를 달성하는 방법에 대해 궁금한 점이 있기 때문일 것입니다.

이 게시물은 Android, BlackBerry 및 iPhone 앱 개발을위한 유용한 치트 시트, 참조 안내서, 빠른 레시피 및 코드 스 니펫을 컴파일합니다. 개발자가 없어서는 안됩니다! 터치 제스처 참조 안내서 (PDF) Desig를위한 귀중한 자원
