简体   繁体   English

让我的按钮类型=“提交”打开另一只手风琴

[英]Make my button type=“submit” open another accordion

On my website which is using Bootstrap3 and I have a page which has 3 accordions on. 在我的使用Bootstrap3的网站上,我的页面上有3个手风琴。 All the accordions have fields and buttons and each has there own process in them. 所有的手风琴都有字段和按钮,每个都有自己的过程。

The issue I have is that when I click my <button type="submit"> from accordion 1, I want it to open accordion 2 (for example). 我遇到的问题是,当我从手风琴1单击我的<button type="submit"> ,我希望它打开手风琴2。 The button has to fire in my code behind so that it terminate the process done in accordion 1 before opening accordion 2. Obviously I cant use <button type="button"> as this doesn't fire in the code behind and I styled a <a> but then realized I couldn't get this to fire in the code behind. 该按钮必须在我后面的代码中触发,以便它在打开手风琴2之前终止在手风琴1中完成的过程。显然,我不能使用<button type="button">因为这不会在后面的代码中触发,因此我将样式设置为<a>但后来意识到我无法在后面的代码中触发它。

One solution I was given was to add href to the button although this isn't supported as it removes everything from my accordions so what other ways can I direct my button to fire in code behind to end my process and then open accordion 2. 我得到的一种解决方案是在按钮上添加href ,尽管这不被支持,因为它删除了我的手风琴中的所有内容,因此我还可以通过什么其他方法指示我的按钮在代码中触发以结束过程,然后打开手风琴2。

Maybe it needs to be done in JavaScript/jQuery or directly in HTML I don't know. 也许需要用JavaScript / jQuery或直接用HTML来完成,我不知道。 I would prefer HTML but I'm open to all suggestions please. 我更喜欢HTML,但是我愿意接受所有建议。

I Googled it and I know that for a button type="button" the following attributes are required data-toggle="collapse" data-parent="NameOfMyParent" 我用Google搜索它,我知道对于button type="button" ,以下属性是必需的data-toggle="collapse" data-parent="NameOfMyParent"

Yes, you have to use javascript (as you already do it with the accordion). 是的,您必须使用javascript(因为您已经在手风琴上使用过javascript)。 I assume you use jquery (as you use Bootstrap). 我假设您使用的是jquery(因为您使用的是Bootstrap)。 So a solution, is to bind an event to prevent the submit (on form submit or on button click), and submit the form with $.ajax() (this can be complex if your form contains some upload process). 因此,一种解决方案是绑定一个事件以防止提交(在表单提交或单击按钮时),然后使用$.ajax()提交表单$.ajax()如果您的表单包含某些上载过程,这可能很复杂)。

$("#your_form_id").on("submit", function(e){
  e.preventDefault();
  var url = $(this).action;
  var data = {};
  /* get your form datas here */
  $.ajax({
    url:url,
    data:data,
    /* use any of theses callback, or none 
     *if you don't care about the request is correct or not
     */
    success:function(res){},
    error:function(res){},
    complete:function(res){
       // call your second accordion here
    }
  })
});

Alternatively, you can use a <input type="button"> and do the opposite work: bind an event to it to fire the submit, or just start the accordion, or anything. 或者,您可以使用<input type="button">并执行相反的工作:将事件绑定到该事件以触发Submit,或者仅启动手风琴,或执行任何操作。

Fixed. 固定。 All i needed to do was add an id to the panel-body and then reference it in my button using data-target 我要做的就是向panel-body添加一个id ,然后使用data-target在我的按钮中引用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM