jQuery 手风琴 - 设置活动手风琴的输入焦点?
**没关系。我想通了。 **
我是这样做的:
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true,
}).bind("change.ui-accordion", function(event,ui) {
$("#text1").focus();
});
我已经设置好了一个手风琴,并且每个 div 中都有一个表单。我只是想弄清楚如何根据打开的输入字段将焦点设置在输入字段上...
/* accordion */
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true
});
基本上,我想将光标设置在打开的部分的第一个输入字段中。实际的形式要大得多,所以我把它压缩得非常大......
<div id="accordion">
<h3 id="section1"><a href="#">Section 1/a></h3>
<div>
<form id="form1" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text1" id="text1" size="50" value="Default text" />
<input class="open" type="button" value="Submit" name="submit1" />
</fieldset>
</form>
</div><!--/div-->
<h3 id="section2"><a href="#">Section 2</a></h3>
<div>
<form id="form2" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text2" id="text2" size="50" value="Submit" />
<input class="open" type="button" value="Submit" name="submit2" />
</fieldset>
</form>
</div><!--/div-->
<h3 id="section3"><a href="#">Section 3</a></h3>
<div>
<form id="form3" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text3" id="text3" size="50" value="Submit" />
<input class="open" type="button" value="Submit" name="submit3" />
</fieldset>
</form>
</div><!--/div-->
**Nevermind. I figured it out. **
I did it like this:
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true,
}).bind("change.ui-accordion", function(event,ui) {
$("#text1").focus();
});
I've got an accordion all set up, and each div has a form within it. I'm just trying to figure out how to set the focus on an input field depending on which one is open...
/* accordion */
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true
});
Basically, I want to set the cursor in the first input field for whichever section is open. The actual forms are much bigger, so I condensed it enormously...
<div id="accordion">
<h3 id="section1"><a href="#">Section 1/a></h3>
<div>
<form id="form1" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text1" id="text1" size="50" value="Default text" />
<input class="open" type="button" value="Submit" name="submit1" />
</fieldset>
</form>
</div><!--/div-->
<h3 id="section2"><a href="#">Section 2</a></h3>
<div>
<form id="form2" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text2" id="text2" size="50" value="Submit" />
<input class="open" type="button" value="Submit" name="submit2" />
</fieldset>
</form>
</div><!--/div-->
<h3 id="section3"><a href="#">Section 3</a></h3>
<div>
<form id="form3" action="form.php" method="post">
<fieldset class="inside">
<input type="text" name="text3" id="text3" size="50" value="Submit" />
<input class="open" type="button" value="Submit" name="submit3" />
</fieldset>
</form>
</div><!--/div-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不适用于其他子手风琴。当您对文本框的 ID 进行硬编码以获取焦点时。
可能可以在change.ui-accordion 事件中加入一些内容,但我对此不太熟悉。你可以使用这样的东西:
这对我来说感觉很老套。
编辑:另请注意,第 1 部分的锚标记未正确关闭。
That's not going to work for the other sub-accordions. As you're hard-coding the ID of the textbox to focus.
It's probably possible to hook into something on that change.ui-accordion event but I'm not terribly familiar with it. You could use something like this:
This feels pretty hacky to me.
Edit: Also note that your anchor tag for Section 1 is not closed properly.
上面提到的两种方法(
.bind("change.ui-accordion"...
和activate: function( event, ui ) {...
) 如果有的话就可以工作只有一个需要关注的输入。我有 3 个文本输入,用户需要能够点击它们来解决这个问题:当然,“:input”可以更改为您需要的任何内容。
The two methods mentioned above (
.bind("change.ui-accordion"...
andactivate: function( event, ui ) {...
) work if there is only one input that needs to be focused. I had 3 text inputs that the user needed to be able to click through. To fix this I used:Of course ":input" can be changed to whatever you need.
最好使用像这样的事件中内置的手风琴,所以
姜是最好的
it's better to use the accordion built in events like so
gingers are the best