找出被点击的项目属于哪个表格 [英] find out which form does the clicked item belongs from

查看:41
本文介绍了找出被点击的项目属于哪个表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的html中有一系列表单,目的是当用户单击继续"按钮时,当前表单消失,而下一个表单出现.但是我想知道是否有一种方法可以获取按下哪个继续"按钮(即哪种形式),以便仅获得一段代码,该代码基本上检查并隐藏当前表单并显示下一个表单而无需ID之类的.

I have a series of forms in my html, the intention is that when the user clicks on the "continue" button, the current one disappears and the next one shows up. However I was wondering if there is a way of getting which "continue" button was pressed (that is, of which form) so to just have a piece of code that basically checks and hides the current form and shows up the next one without requiring id's or such.

我尝试了几件事,但没有任何效果,因此我不会在此处发布代码(说实话,它只是破坏"了网站.

I tried a couple of things but none worked so I won't be posting here the code (it honestly just "broke" the website anyways.

推荐答案

如果您使用 jQuery :

$(function() {
   // Attach click handler to your buttons
   $("button, input[type=submit]").click(function(e) {
      e.preventDefault();
      // Hide the correct form
      var thisForm = $(this).parents("form").hide();
      // Show the form after this one
      thisForm.nextAll("form:first").show();
   });
});

这也将为您处理隐藏和显示表单的问题.假定您的按钮是< button> < input type ="submit"> ,并且您的表单元素在同一父项中.

That'll handle hiding and showing the forms for you too. It assumes your buttons are either <button> or <input type="submit">, and your form elements are within the same parent.

当然,如果页面上其他位置的按钮没有这种行为,那么您需要向感兴趣的按钮中添加诸如 formContinue 之类的类,并更改第三行在上面的代码中:

Of course, if you have buttons elsewhere on the page which don't have this behaviour, then you need to add a class such as formContinue to your buttons of interest, and change the third line in the code above to:

$("button.formContinue, input[type=submit].formContinue").click(function(e) {

这篇关于找出被点击的项目属于哪个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆