私は以下のように、1つの名前の2つのラジオボタンからなるフォーム入力を持っています:
<input type="radio" name="type" value="thumb" checked />
<input type="radio" name="type" value="img" />
jQuery関数内では、どのようなものがチェックされているかを参照します。
type=$('input[name="type"]').is(':checked').val();
何らかの理由で、たとえ私がページ上のチェックボックスを変更したとしても、常に前者を返します。
削除の目的で、完全なコードは次のとおりです。
<html>
<head>
<title>Thumb/img BBCode generator</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
Thumb/img BBCode generator for Facepunch
<div id="content">
<form id="f" action="generate2.php" method="POST">
<input type="radio" name="type" value="thumb" checked />
<input type="radio" name="type" value="img" />
<input type="button" value="Generate!" id="1_c"/>
</form>
</div>
<script>
$('#1_c').click(function(){
var text=$('textarea').val(),
type=$('input[name="type"]').is(':checked').val();
$.post('generate2.php', { text: text, type: type },
function(data) {
$("#content").html(data);
});
});
function reset(){
history.go('0');
}
</script>
</body>
Live version: http://pdo.elementfx.com/thumb/