簡體   English   中英

在HTML中使用多種形式

[英]Using multiple forms in HTML

我在一個HTML頁面中有四種形式( MainFormLandedApartmentCondominium )。

<body>

        <form name="MainForm" method="post">
            <input type="radio" name="type" value="Landed">Landed
            <input type="radio" name="type" value="Apartment">Apartment
            <input type="radio" name="type" value="Condominium">Condominium
        </form>

        <form name="Landed" method="post"> </form>

        <form name="Apartment" method="post"></form>

        <form name="Condominium" method="post"></form>
</body>

MainForm具有三個單選按鈕。 如果按下Landed單選按鈕,則Landed表單將與MainForm一起加載。 或選擇其他單選按鈕,將加載它們各自的形式。 在進行任何選擇之前,所有表單都將被隱藏。 然后僅在按下單選按鈕時顯示。 最好的方法是什么? 我試過了,所有表格都被加載了。

謝謝

如果您所做的只是基於選定的單選按鈕顯示/隱藏表單,則可以基於form元素的id屬性使用showhide ,如下所示:

<form id="mainform" name="mainform" method="post">
    <input type="radio" name="type" value="landed">Landed
    <input type="radio" name="type" value="apartment">Apartment
    <input type="radio" name="type" value="condominium">Condominium
</form>

<form id="landed" name="landed" method="post">
    Landed form
</form>

<form id="apartment" name="apartment" method="post">
    Apartment form
</form>

<form id="condominium" name="condominium" method="post">
    Condominium form
</form>
$('#mainform input[type="radio"]').change(function() {
    $('form:not(#mainform)').hide();
    $('#' + this.value).show();
});

小提琴的例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM