JQuery焦点 [英] JQuery focus
本文介绍了JQuery焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div id =content>
< div id =firstP>< p>第一段< / p>< / div>
< div id =secondP>< p>第二段< / p>< / div>
< div id =thirdP>< p>第三段< / p>< / div>
< div id =fourthP>< p>第四段< / p>< / div>
< / div>
我想用Javascript添加一个新的div,并关注这个新的元素。焦点不做任何事情。
函数addParagraph(){
var html =< div id = \newP\> ;< p>新段落< / p>< / div>;
$(#content)。append(html);
$(#newP)。focus();
$ b $ p
$ b $ p
$ div $ h2_lin>解决方案
我认为主要答案是不正确的。 DIV和P标签可以获得焦点,只要您为它们指定tabindex属性即可。即
< div class =someclasstabindex =100>
一旦tabindex被指定,您可以选择这些元素或使用 .focus ()。
使用scrollTo插件似乎在这里有点矫枉过正。
Let say i have the next markup:
<div id="content">
<div id="firstP"><p>First paragraph</p></div>
<div id="secondP"><p>Second paragraph</p></div>
<div id="thirdP"><p>Third paragraph</p></div>
<div id="fourthP"><p>Fourth paragraph</p></div>
</div>
I want to add a new div with Javascript and focus in this new element. Focus does not do anything.
function addParagraph() {
var html = "<div id=\"newP\"><p>New paragraph</p></div>";
$("#content").append(html);
$("#newP").focus();
}
Any idea?
解决方案
I think the main answer is incorrect. DIV and P tags can receive focus providing you specify a tabindex property for them. i.e.
<div class="someclass" tabindex="100">
Once the tabindex is specified you can either tab to these elements or shift focus with .focus() .
Using a scrollTo plugin seems like a bit of an overkill here.
这篇关于JQuery焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文