簡體   English   中英

僅在選擇單選按鈕時才包含頁面

[英]Include page only when radio button selected

我對Javascript和jquery完全陌生,但是我有一個頁面和3種形式。 表單位於外部文件中。 我需要選擇單選按鈕1,出現表格1,選擇單選按鈕2,形成表格2,依此類推。

謝謝。

湯姆

您可以使用ajax做到這一點,如下所示:

的HTML

<div id="ajax-form"></div>
<input class="radio-1" type="radio">

jQuery的

$('.radio-1').on('click', function() {
    $.ajax({
        type: 'GET',
        url: 'form-1.html',
        complete: function(data) {
            $('#ajax-form').html(data);
        }
    });
});

$('.radio-2').on('click', function() {
    $.ajax({
        type: 'GET',
        url: 'form-2.html',
        complete: function(data) {
            $('#ajax-form').html(data);
        }
    });
});

...

我做了一個jsfiddle演示,向您展示了您通常如何實現這一目標。

var $button = $(".button"),
    $paragraph = $(".sometext");

$button.click(function (event) {
    // do something when ".a_button" is clicked.
    $paragraph.toggle();
    // there are many functions like .toggle
    // Take a look at .show and .hide, .slide, .animate and .fade
})

干得好

暫無
暫無

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

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