如何在单击按钮时隐藏表单

斯里哈里

我试图隐藏表单,并在单击按钮时显示必要的表单。但是javascript代码无法正常工作。jfiddle链接:https ://jsfiddle.net/5d28uLkL/
请改正错误(如果有)

HTML:

<div class="nav">
<button href="#" data-category-type="high">CRSS</button>

<button href="#" data-category-type="low">TUBU</button>


<div id="Categories">

<div class="container" data-category-type="high">


            <div class="fs-form-wrap" id="fs-form-wrap">
                <div class="fs-title">
                    <h1>CR Strips</h1>
                </div>
                <form id="myform" class="fs-form fs-form-full" autocomplete="off">
                    <ol class="fs-fields">
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q1">Company's Name</label>
                            <input class="fs-anim-lower" id="q1" name="q1" type="text" placeholder="" required/>
                        </li>
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q2">Contact Person</label>
                            <input class="fs-anim-lower" id="q2" name="q2" type="text" placeholder="" required/>
                        </li>
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q3">Phone</label>
                            <input class="fs-anim-lower" id="q3" name="q3" type="text" placeholder="" required/>
                        </li>




                    </ol><!-- /fs-fields -->
                    <button class="fs-submit" type="submit">Send answers</button>
                </form><!-- /fs-form -->
            </div><!-- /fs-form-wrap -->
      </div>








<div class="container" data-category-type="low">


            <div class="fs-form-wrap" id="fs-form-wrap1">
                <div class="fs-title">
                    <h1>TUBE</h1>
                </div>
                <form id="myform" class="fs-form fs-form-full" autocomplete="off">
                    <ol class="fs-fields">
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q1">Company's Name</label>
                            <input class="fs-anim-lower" id="q1" name="q1" type="text" placeholder="" required/>
                        </li>
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q2">Contact Person</label>
                            <input class="fs-anim-lower" id="q2" name="q2" type="text" placeholder="" required/>
                        </li>
                        <li>
                            <label class="fs-field-label fs-anim-upper" for="q3">Phone</label>
                            <input class="fs-anim-lower" id="q3" name="q3" type="text" placeholder="" required/>
                        </li>



                    </ol><!-- /fs-fields -->
                    <button class="fs-submit" type="submit">Send answers</button>
                </form><!-- /fs-form -->
            </div><!-- /fs-form-wrap -->
</div>

        </div>
    </div>

JAVASCRIPT:

    $('.nav a').on('click', function (e) {
    e.preventDefault();
    var cat = $(this).data('categoryType');
    var nam = $(this).data('categoryName');
    $('#Categories > div').hide();
    $('#Categories > div[data-category-type="'+cat+'"]').show();
    $('#Categories > div[data-category-name="'+nam+'"]').show();
});
阿什温

只需为使用的按钮提供ID,然后将其链接到js。

HTML:

<button id="high" href="#" data-category-type="high">CRSS</button>
<button id="low" href="#" data-category-type="low">TUBULAR COMPONENTS</button>

JS:

$('#high').on('click',function(){
     $('#fs-form-wrap').show();
     $('#fs-form-wrap1').hide();
 });
  $('#low').on('click',function(){
     $('#fs-form-wrap1').show();
     $('#fs-form-wrap').hide();
 });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在单击按钮时显示隐藏的div并在Angular 2中隐藏单击的按钮?

Angular ,如何在单击按钮时隐藏表格行

如何在按钮单击时应用显示和隐藏?

如何在按钮单击时隐藏 Bootstrap 5 模式

如何在单击按钮时显示和隐藏局部视图?

如何在单击按钮时使用JavaScript隐藏SVG元素?

如何在签出按钮单击时触发表单验证

如何在单击按钮时使用HTML表单验证?

BootstrapVue:如何在单击按钮时关闭弹出窗口/表单

单击按钮时如何从页面(Bootstrap 4)隐藏或删除搜索表单?

单击按钮时如何隐藏文本

在Flask中单击按钮时隐藏/显示表单

在Visual Basic表单中单击时隐藏动态创建的按钮

如何在单击按钮时同时运行表单操作和单击事件

单击按钮时如何清除表单?

单击不同按钮时如何提交表单

单击时如何更改表单的按钮

单击按钮时如何防止表单提交?

单击不应该发送表单的按钮时,如何在Angular中关闭表单验证

单击单个按钮时如何隐藏 2 个离子按钮?

单击按钮时如何在javascript中隐藏/显示下拉菜单

如何在单击按钮时向上/向下滑动隐藏的div?

如何在单击按钮时获取最接近的隐藏输入字段的值

如何在使用 Tableau Reader 单击 Tableau 按钮时隐藏下拉菜单

单击模态内的按钮时如何在Angular 7中隐藏组件?

如何在加减按钮单击时显示显示/隐藏表格

如何在按钮单击下一个活动时隐藏或显示元素

当使用JavaScript单击表单时,如何隐藏表单并显示链接onclick以及隐藏表单并显示链接

如何在 Angular 7 中单击按钮时添加表单元素