jQuery-根据单选单击更改标签文本 [英] jQuery - Changing label text based on radio click
本文介绍了jQuery-根据单选单击更改标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道jQuery是否可以根据单击的单选按钮来更改页面上的文本.
I was wondering if it is possible with jQuery to change text on a page based on what radio button is clicked.
我有以下代码,我想根据单击的单选按钮将标签文本更改为单击了第一个单选"或单击了第二个单选".
I have the following code, and i want to change the label text to "first radio was clicked" or "second radio was clicked" based on which of the radio buttons were clicked.
<input type="radio" name="first" value="yes" id="firstradio">
<input type="radio" name="first" value="no" id="secondradio">
<label class="changeme">Initial text goes here and is happy</label>
推荐答案
如下所示:
$('input[name=first]').change(function() {
// change the page per this logic
switch ($('input[name=first]:checked').val()) {
case 'yes':
$('#Message').text('first radio was clicked'); break;
case 'no':
$('#Message').text('second radio was clicked'); break;
default:
$('#Message').text('select choice');
};
这篇关于jQuery-根据单选单击更改标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文