如何确定在手风琴中单击了哪个索引的按钮
我正在使用 jQuery Accordion UI 和多部分表单(带验证和表单插件)。每个表单都有一个常规的提交按钮和一个编辑按钮。如果当前打开的部分已完成,编辑按钮将触发该部分的提交;如果该部分尚未完成,则关闭该活动部分。然后,手风琴将打开到单击编辑按钮的部分。
例如,用户填写第 1 部分,然后单击继续。在填写第 2 部分时,用户意识到自己犯了一个错误,并单击第 1 部分中的编辑按钮。第 2 部分关闭,第 1 部分重新打开进行编辑。我想知道哪个索引包含触发第 2 部分关闭的编辑按钮(在本例中,它是与第一个部分关联的索引)。
我无法弄清楚如何确定从哪个部分(索引)单击了编辑按钮。当我在 commitHandler 中使用以下代码时,我没有获得正确的索引。
var acc = $("#accordion"),
index = acc.accordion('option','active'),
index_origin = $(".edit").index(this);
alert(index_origin);
有什么建议吗?
我提前为笨拙的代码道歉 - 我对此很陌生。
更新:下面,根据评论中的要求,这里是手风琴第一部分的 HTML。
<h3 id="section1"><a href="#" class="">Applicant Information</a><button id="edit-applicant-button" class="edit" value="edit" name="edit">Edit Applicant information</button></h3>
<div id="applicant-information" class="step">
<form id="applicant-form" class="registration-form" name="applicant-form" method="post" action="">
<fieldset id="clientInfo">
. . .
</div>
<div class="step-action">
<p>
<span class="next-step">
<button id="submit-first" class="submit" type="submit" value="next" name="next"><em>Next</em></button>
</span>
</p>
</div><
</fieldset>
</form>
</div>
I am using jQuery Accordion UI with a multipart form (w/ validation and form plugins). Each form has a regular submit button and an edit button. The edit button will trigger a submission of the currently open section if that section is complete, or close that active section if it is not yet completed. The accordion will then open to the section where the edit button was clicked.
For example, user fills in section 1, then clicks continue. While filling in section 2, the user realizes that he or she made a mistake and clicks on the edit button within section 1. Section 2 is closed, and section 1 is reopened for editing. I would like to know which index contained the edit button that triggered section 2 to close (in this instance it was the index associated with the first section).
I cannot figure out how to determine from which section (index) the edit button was clicked. When I use the following code within the submitHandler, I do not get the correct index.
var acc = $("#accordion"),
index = acc.accordion('option','active'),
index_origin = $(".edit").index(this);
alert(index_origin);
Any suggestions?
I apologize in advance for the clumsy code - I'm new to this.
UPDATE: Below, as requested in the comments, here is the HTML from the first section of the accordion.
<h3 id="section1"><a href="#" class="">Applicant Information</a><button id="edit-applicant-button" class="edit" value="edit" name="edit">Edit Applicant information</button></h3>
<div id="applicant-information" class="step">
<form id="applicant-form" class="registration-form" name="applicant-form" method="post" action="">
<fieldset id="clientInfo">
. . .
</div>
<div class="step-action">
<p>
<span class="next-step">
<button id="submit-first" class="submit" type="submit" value="next" name="next"><em>Next</em></button>
</span>
</p>
</div><
</fieldset>
</form>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误是按钮的实际类是
"edit"
,而不是"editButton"
。因此,您必须在 html 中更改它,或者将您的 javascript 更改为:将
#accordion
添加到选择器不是强制性的,但将允许您拥有一个或多个手风琴。编辑。根据您提供的额外信息,解决方案如下:
The error is that the actual class of your button is
"edit"
, not"editButton"
. So you'd have to change it in the html, OR change your javascript to this:Adding the
#accordion
to the selector is not mandatory, but will allow you to have one or many accordions.EDIT. With the extra information you supplied, the solution would be this:
手风琴中选定的部分给出了活动类。您找到具有活动类的
h
标记The selected section in accodion gives the active class. You find the
h
tag that has the active class