我在页面上有这些单选按钮,按钮可以转到下一页。 (被称为'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>
答案 0 :(得分: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);
})
这是小提琴中的工作示例..检查出来
答案 1 :(得分:0)
如果你使用jQuery,你可以这样做:
var val = $('input[name="categorie-oordeel"]:checked').val();
$('#CatNaam').text(val);