简体   繁体   English

根据带有类标记的下拉菜单选择隐藏/显示表单字段

[英]hide/show form fields based on dropdown choice with class tag

I have a problem with the show/hide function on an app form. 我在应用程序窗体上的显示/隐藏功能有问题。 The app form is live here -> http://www.specialfinance.co.uk/introducers/submit-an-enquiry/secured-loans.html 该应用程序表单位于此处-> http://www.specialfinance.co.uk/introducers/submit-an-enquiry/secured-loans.html

Currently the form works as a multipage form (within javascript) which is fine, it's doing the job nicely, but what I can't figure out based on any of the Q&A guides I've looked thru on here (I've gone thru many google searches) is how to integrate a further show/hide script to hide the applicant 2 column if the dropdown at the top has a value of 1. 目前,该表单可以用作多页表单(在javascript中),很好,可以很好地完成工作,但是根据我在这里浏览过的任何问答指南,我都无法弄清楚(我已经遍历了许多Google搜索)是如何集成进一步的显示/隐藏脚本以隐藏申请人2列(如果顶部的下拉列表的值为1)。

The column is a table with all the inputs in separate rows, so I was thinking that the easiest way would be to link to a class and then hide the class, but I have no idea how to do this. 该列是一个表格,所有输入都放在单独的行中,因此我认为最简单的方法是链接到一个类,然后隐藏该类,但是我不知道该怎么做。

I'm getting there with my knowledge of javascript, but this one seems to be a hurdle I can't get over. 我是凭着对javascript的了解到达那里的,但这似乎是我无法克服的障碍。

You can use the .change() (jQuery) with the dropdown list to see what the value is, then based off that, hide and show what you need. 您可以在下拉列表中使用.change()(jQuery)来查看值,然后基于该值隐藏并显示所需的内容。

$("#idOfDropDown").change(function() {
    if ($(this).val() == 1) {
        //Show  or Hide what you need .show()
    }
    else {
        //Show or Hide .hide()
});

Heres a demo: http://jsfiddle.net/Szt59/1/ using a class. 这是一个演示:使用类的http://jsfiddle.net/Szt59/1/

Here is a quick and dirty example. 是一个简单又肮脏的例子。 It's easy to see how you can extend it. 很容易看到如何扩展它。

$("#drop").change(function(){
    if( $(this).val() === "2" ) {
         $(".rest").slideDown("fast");   
    } else {
       $(".rest").slideUp("fast");     
   }
});

Click to see demo Edited. 单击以查看演示已编辑。

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

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