我要創建3個單選按鈕供用戶選擇。一旦用戶點擊該按鈕,它將向用戶顯示用戶選擇的那個單選按鈕的描述。如何根據用戶選擇的單選按鈕更改要顯示的內容?
例如
- if user select first radio button ==> it will show the description under that
radio button
- if user select second radio button ==> it will show the description under that
radio button
- if user select third radio button ==> it will show the description under that
radio button
我的代碼
<p><input type='radio' name='content_type' value='1' /> This is content A of request</p>
<p><input type='radio' name='content_type' value='2' /> This is content B of request</p>
<p><input type='radio' name='content_type' value='3' /> This is content C of request</p>
<div id='show'></div>
的Javascript
$(document).ready(function(){
$('#content_type').on('change', function(){
var n = $(this).val();
switch(n)
{
case '1':
document.getElementById('#show').innerHTML="1st radio button";
break;
case '2':
document.getElementById('#show').innerHTML="2nd radio button";
break;
case '3':
document.getElementById('#show').innerHTML="3rd radio button";
break;
}
});
我的代碼以上沒」工作。任何人都可以幫助我展示這個問題嗎?
預先感謝
它工作:)謝謝! – user2738520