将值更改为选中的单选按钮的值

问题描述 投票:0回答:2

我在页面上有这些单选按钮和一个转到下一页的按钮。 (称为“Doorgaan”)。在下一页中,我有一个 ID 为“CatNaam”的 h2,我希望将其值 [CATEGORIENAAM] 更改为选中的单选按钮的值。 我该怎么做?

    <div data-role="page" id="beoordelen" data-theme="a">

        <div data-role="header">
            <h1>Beoordelen</h1>
            <a class="ui-btn-left" data-theme="a" data-rel="back">Vorige</a>
        </div><!-- /header -->

        <div data-role="content" data-theme="a">    
            <h2>Kies categorie</h2>
            <form id="oordeelKeuze" method="get">
                   <p>      
                      <input type = "radio" name = "categorie-oordeel" id = "goedkoop-bier" value = "Goedkoop bier" checked = "checked" />
                      <label for = "goedkoop-bier">Goedkoop bier</label>
                   </p><p>                    
                      <input type = "radio" name = "categorie-oordeel" id = "muziek" value = "Muziek" />
                      <label for = "muziek">Muziek</label>
                    </p><p>      
                      <input type = "radio" name = "categorie-oordeel" id = "gezelligheid" value = "Gezelligheid" />
                      <label for = "gezelligheid">Gezelligheid</label>
                    </p>   
            </form>
            <p><a href="#beoordelen2" data-direction="reverse" data-role="button" data-theme="b">Doorgaan</a></p>   

        </div><!-- /content -->


    </div><!-- /beoordelen -->

    <!-- Start of fifth page: #beoordelen2 -->
    <div data-role="page" id="beoordelen2" data-theme="a">

        <div data-role="header">
            <h1>Beoordelen</h1>
            <a class="ui-btn-left" data-theme="a" data-rel="back">Vorige</a>
        </div><!-- /header -->

        <div data-role="content" data-theme="a">    
            <h2>Geef cijfer voor</h2>
            <h2 id="CatNaam">[CATEGORIENAAM]</h2>
</div>
</div>
javascript jquery-mobile
2个回答
1
投票

使用 jQuery,为您的按钮 (Doorgaan) 提供一个 id:

 <p><a href="#beoordelen2" data-direction="reverse" data-role="button" data-theme="b" id="buttonID">Doorgaan</a></p>   //buttonID in this case

然后在您的按钮(Doorgaan)上单击添加以下内容:

$('#buttonID').click(function(){
   var selectedRadio= $("input[type='radio'][name='categorie-oordeel']:checked").val();
  $('#CatNaam').text(selectedRadio);
})

这是小提琴中的工作示例:

http://jsfiddle.net/F5brz/


0
投票

如果你使用jQuery,你可以这样做:

var val = $('input[name="categorie-oordeel"]:checked').val();
$('#CatNaam').text(val);
© www.soinside.com 2019 - 2024. All rights reserved.