복붙노트

[JQUERY] '$ (이)'와 '이'의 차이점은 무엇입니까?

JQUERY

'$ (이)'와 '이'의 차이점은 무엇입니까?

해결법


  1. 1.당신이 jQuery를 사용할 때 예 만 $ ()를해야합니다. 당신이 jQuery의 도움 DOM의 일을하려면 바로이 점을 명심.

    당신이 jQuery를 사용할 때 예 만 $ ()를해야합니다. 당신이 jQuery의 도움 DOM의 일을하려면 바로이 점을 명심.

    $(this)[0] === this
    

    기본적 요소의 집합을 얻을 때마다 jQuery를이 jQuery를 객체로 바뀝니다 백업합니다. 당신은 하나의 결과 만이 알고있는 경우에, 첫 번째 요소에있을 것입니다.

    $("#myDiv")[0] === document.getElementById("myDiv");
    

    등등...


  2. 2.$ ()는 jQuery를 생성자 함수입니다.

    $ ()는 jQuery를 생성자 함수입니다.

    이는 호출의 DOM 요소에 대한 참조이다.

    그러니까 기본적으로, $에 (이), 당신은 당신이 jQuery를 방법과 함수를 호출 할 수 있도록 매개 변수로 $ ()에이 전달된다.


  3. 3.예, jQuery를 기능에 (이) $ 필요는 없지만, 당신이 jQuery를 사용하지 않는 요소의 액세스 기본 자바 스크립트 방법으로 할 때, 당신은이를 사용할 수 있습니다.

    예, jQuery를 기능에 (이) $ 필요는 없지만, 당신이 jQuery를 사용하지 않는 요소의 액세스 기본 자바 스크립트 방법으로 할 때, 당신은이를 사용할 수 있습니다.


  4. 4.jQuery를 사용하는 경우, 일반적으로 $ (이)를 사용하는 것이 좋습니다. 당신이 알고있는 경우 그러나 차이를 (당신이 배우고 알아야한다), 때때로는 더 편리하고 더 빠른 단지 이것을 사용 할 수 있습니다. 예를 들어 :

    jQuery를 사용하는 경우, 일반적으로 $ (이)를 사용하는 것이 좋습니다. 당신이 알고있는 경우 그러나 차이를 (당신이 배우고 알아야한다), 때때로는 더 편리하고 더 빠른 단지 이것을 사용 할 수 있습니다. 예를 들어 :

    $(".myCheckboxes").change(function(){ 
        if(this.checked) 
           alert("checked"); 
    });
    

    보다 쉽고 순수한입니다

    $(".myCheckboxes").change(function(){ 
          if($(this).is(":checked")) 
             alert("checked"); 
    });
    

  5. 5.이것은 요소 $이고 (이)가 그 구성 요소 jQuery 오브젝트는

    이것은 요소 $이고 (이)가 그 구성 요소 jQuery 오브젝트는

    $(".class").each(function(){
     //the iterations current html element 
     //the classic JavaScript API is exposed here (such as .innerHTML and .appendChild)
     var HTMLElement = this;
    
     //the current HTML element is passed to the jQuery constructor
     //the jQuery API is exposed here (such as .html() and .append())
     var jQueryObject = $(this);
    });
    

    더 깊은보기

    thisMDN가 실행 컨텍스트에 포함


  6. 6.그래, $를 사용하여 (이), 당신은 객체의 jQuery 기능을 사용 가능. 그냥이를 사용하여, 그것은 단지 일반적인 자바 스크립트 기능이 있습니다.

    그래, $를 사용하여 (이), 당신은 객체의 jQuery 기능을 사용 가능. 그냥이를 사용하여, 그것은 단지 일반적인 자바 스크립트 기능이 있습니다.


  7. 7.jQuery를 함께 캡슐화하는데 사용 기준이 자바 스크립트 객체와 $ (이).

    jQuery를 함께 캡슐화하는데 사용 기준이 자바 스크립트 객체와 $ (이).

    예 =>

    // Getting Name and modify css property of dom object through jQuery
    var name = $(this).attr('name');
    $(this).css('background-color','white')
    
    // Getting form object and its data and work on..
    this = document.getElementsByName("new_photo")[0]
    formData = new FormData(this)
    
    // Calling blur method on find input field with help of both as below
    $(this).find('input[type=text]')[0].blur()
    
    //Above is equivalent to
    this = $(this).find('input[type=text]')[0]
    this.blur()
    
    //Find value of a text field with id "index-number"
    this = document.getElementById("index-number");
    this.value
    
    or 
    
    this = $('#index-number');
    $(this).val(); // Equivalent to $('#index-number').val()
    $(this).css('color','#000000')
    
  8. from https://stackoverflow.com/questions/1051782/whats-the-difference-between-this-and-this by cc-by-sa and MIT license