jQuery手风琴-为活动手风琴设置输入焦点?
**别客气。我想出来了** 我是这样做的:jQuery手风琴-为活动手风琴设置输入焦点?,jquery,input,focus,accordion,Jquery,Input,Focus,Accordion,**别客气。我想出来了** 我是这样做的: $("#accordion").accordion({ header:'h3', active: '#section1', autoheight: false, clearstyle: true, }).bind("change.ui-accordion", function(event,ui) { $("#text1").focus(); }); $(document)
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true,
}).bind("change.ui-accordion", function(event,ui) {
$("#text1").focus();
});
$(document).ready(function() {
$("div#accordion > h3 > a").click(function(e) { // when we click a link
e.preventDefault(); // prevent the click from bubbling
var parenth3 = $(this).parent(); // find the parent h3 the sender is in
//this selector then finds the first textbox that is in the div adjacent to the parent h3.
$("#" + parenth3[0].id + " + div > form > fieldset.inside > input[type=text]:first").focus();
});
});
我已经准备好了一个手风琴,每个部门都有一个表格。我只是想弄清楚如何根据打开的输入字段设置焦点
/* 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-->
这对其他亚手风琴不起作用。当您硬编码文本框的ID以聚焦时
也许可以在change.ui-accordion事件中加入一些东西,但我对它不是很熟悉。您可以使用以下内容:
$("#accordion").accordion({
header:'h3',
active: '#section1',
autoheight: false,
clearstyle: true,
}).bind("change.ui-accordion", function(event,ui) {
$("#text1").focus();
});
$(document).ready(function() {
$("div#accordion > h3 > a").click(function(e) { // when we click a link
e.preventDefault(); // prevent the click from bubbling
var parenth3 = $(this).parent(); // find the parent h3 the sender is in
//this selector then finds the first textbox that is in the div adjacent to the parent h3.
$("#" + parenth3[0].id + " + div > form > fieldset.inside > input[type=text]:first").focus();
});
});
这让我感觉很不舒服
编辑:还请注意,第1节的锚定标记未正确关闭。最好使用手风琴内置事件,如
$(".accordion").accordion({
beforeActivate: function() {},
activate: function( event, ui ) {
$(ui.newPanel).find('input')[0].focus()
}
});
Ginger是最好的上述两种方法(
.bind(“change.ui accordion”…
和activate:function(event,ui){…
)在只有一种输入需要聚焦的情况下有效。我有3种文本输入,用户需要能够点击。为了解决这个问题,我使用了:
$(":input").click(function() {
$(this).focus();
});
当然“:input”可以更改为您需要的任何内容。如果我有一个保存按钮并单击保存按钮事件,如果我想设置焦点,如何实现它?奇怪的是,如果beforeActivate功能不存在,它就无法工作