jQuery 코드 스 니펫은 현재 초점을 가진 요소를 얻고 초점이 느슨해지면 Ajax 자동 저장을 수행합니다.
<span>//get active element of focus using js </span><span>$(document.activeElement)</span>
<span>//change focus when tabbed across into new item </span><span>$('.item :input').live('focus', function() </span><span>{ </span> <span>var thisItem = $(this).parents('.item'); </span> <span>var thisId = thisItem.attr('id'); </span> <span>$('.item').removeClass('item-selected'); //remove all focus </span> thisItem<span>.addClass('item-selected'); //add focus to current item </span> <span>//save those items that have changed </span> $<span>.each($('.item-changed'), function(i<span>,v</span>) </span> <span>{ </span> <span>var currItemId = $(this).attr('id'); </span> <span>//exclude current item </span> <span>if (!_this.helpers.itemHasFocus(currItemId)) </span> <span>{ </span> <span>console.log('saving '+currItemId); </span> _this<span>.save.item(currItemId); /* AJAX auto save */ </span> <span>$(this).removeClass('item-changed'); </span> <span>} </span> <span>}); </span><span>});</span>
jQuery를 사용하여 특정 요소에 초점을 맞출 수 있습니까?
예, jQuery를 사용하여 특정 요소에 초점을 맞출 수 있습니다. Focus () 메소드는 특정 요소에 초점을 설정하는 데 사용됩니다. 예는 다음과 같습니다.
$ ( " #myelement"). focus ();
이 코드에서 #MyElement는 초점을 설정하려는 요소의 ID입니다.
jquery를 사용하여 요소에서 포커스를 제거하려면 요소에서 초점을 제거하려면 blur () 방법을 사용할 수 있습니다. 예는 다음과 같습니다.
alert ( "요소가 포커스가 됨"); );이 코드에서, #MyElement gains 초점에 초점을 맞출 때 경고가 트리거 될 때 경고가 트리거 될 때 경고가 트리거 될 때 경고가 트리거 될 때 경고가 트리거 될 때 경고가 트리거 될 수 있습니까? jQuery에서 Blur () 메소드를 사용하여 초점을 잃습니다. Here’s an example:
$("#myElement").blur(function(){
alert("Element has lost focus");
How can I check if an element has focus using jQuery?
To check if an element has focus, you can jQuery에서 IS ( ": Focus") 메소드를 사용하십시오. 예는 다음과 같습니다. if ($ ( " #mylement"). is ( ": focus")) {} else {
$ ( "input"). focus ();
이 코드에서 DOM의 첫 번째 입력 요소는 초점을 얻을 수있는 방법입니다.
jquery를 사용하여 다음 입력 필드에 초점을 맞출 수 있습니까? 다음 입력 필드. 예는 다음과 같습니다.
이 코드에서 Dom의 첫 번째 링크는 포커스가됩니다. .
위 내용은 jQuery는 현재 초점을 가진 요소를 얻습니다의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!