如何在html表单之间切换/选择 [英] how to switch/choose between html forms

查看:151
本文介绍了如何在html表单之间切换/选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,需要你的专业...

所以我在两个div中有两种形式。 DIV ID = A和DIV ID = B



当用户访问我的网站时,访客在表格之间进行选择。他用户看到一个下拉框,或两个单选按钮,如果选择选项A,然后形成一个负载,如果B ...然后乙..

但我不不知道该怎么做,这样做的最佳做法是什么?我可以使用简单的HTML,并选择重定向到像formA.php和formB.php子页面?或者使用JQuery和简单的隐藏并显示所需的div?



ya提示什么?如何做到这一点?



比你。

解决方案

jquery或类似将是最优雅的imo。类似于

 < script type =text / javascript> 
$(document).ready(function(){
//当页面准备就绪时隐藏表单
$('#a')。hide();
$( '#b')。hide();

$('#button1')。click(function(){
$('#a')。show(); $ b ();
$('#button2')。click(function(){
$('#b')。show();
});
});
< / script>

隐藏表格,有2个按钮(可以是样式化的div)。然后当它们被点击时,显示相应的HTML表单。



可以扩展为切换表单,或者只允许选择1。 b
$ b

如果JS被禁用,可能会出现问题(两种形式都可见)


I have a little problem, and an need your profesisonal...

So i have two forms in two div. DIV ID=A and DIV ID=B

When a user visit my site, a would like to offer the visitor to choose between the forms. he user see a drop down box, or two radio button, and if select option A then form A load, if B...then B..

But i don't know how to do this, and what is the best practise to do this? May i use simple html, and after choose redirect to a subpage like formA.php and formB.php? Or use Jquery and simple hide and show the needed div?

What do ya suggest? And how im a do that?

Than you.

解决方案

Jquery or similiar would be the most elegant imo. something like

<script type="text/javascript">
$(document).ready(function() {
    // hide the forms when page is ready
    $('#a').hide();
    $('#b').hide();

    $('#button1').click(function(){ 
        $('#a').show(); 
    });
    $('#button2').click(function(){ 
        $('#b').show(); 
    });
});
</script>

hide the forms, have 2 buttons (can be styled divs),. then when they are clicked, show the respective HTML form.

could be extended to "toggle" the forms, or only allow 1 to be selected.

problems may occur if JS is disabled however (both forms will be visible)

这篇关于如何在html表单之间切换/选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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