<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>
$(document).ready(function(){
var pocusiselement = $(':focus');
console.log(focusedElement);
});
});
在此代码中,:focus focus focus Selects当前具有focus和console.log(pocuseDusedElement)的元素,将重点元素打印到控制台。
设置专注于特定元素,是的,您可以使用jQuery设置专注于特定元素。焦点方法用于将重点放在特定元素上。 Here’s an example:
$("#myElement").focus();
In this code, #myElement is the id of the element you want to set focus on.
To remove focus from an element, you can use the blur() method in jQuery.以下是一个示例:
$(“#myelement”)。blur();
在此代码中,#myelement是您要从中删除的元素的ID。
$("#myElement").focus(function(){
alert("Element has gained focus");
});
In this code, an alert is triggered when #myElement gains focus.
Can I trigger an event when an element loses focus?
$(“#myElement”)。blur(function(){
>警报(“元素失去焦点”);
});
});
>在此代码中,警报将在#myElement丢失焦点时触发时触发pocus。 IS(“:focus”)方法中的方法。 Here’s an example:
console.log("Element does not have focus"); $(“ input”)。focus(); $(“ a”)。focus();
}
In this code, a message is printed to the console depending on whether #myElement has focus or当页面加载时,我可以将重点放在元素上,不是。以下是一个示例:
$(document).ready(function(){
});
在此代码中,#MyElement foce foce当页面加载时。>我可以使用jQuery专注于表单输入吗?焦点方法可用于将重点放在表单输入上。以下是一个示例:
在此代码中,dom增益中的第一个输入元素焦点中的第一个输入元素。
>
我如何使用jQuery专注于下一个输入字段时,当Enter键被按下express in jeypress in jepress in jepress intect in jepress in je quey in jepress in je quey ins jepress()下一个输入字段。以下是一个示例: $(“ input”)。键(function(e){e){
在此代码中,dom Goins focus中的第一个链接。
以上是jQuery获得当前重点的元素的详细内容。更多信息请关注PHP中文网其他相关文章!