または、これを自分で行いたい場合...
私がすることは、<button>
要素と非表示のフォームフィールド要素を使用してボタンを作成し、どのボタンが「押された」かを次のように記憶することです。
<button type="button" id="btn1">Choice 1</button>
<button type="button" id="btn2">Choice 2</button>
<button type="button" id="btn3">Choice 3</button>
<input type="hidden" id="btnValue" value="" />
ボタンが「押されている」か「押されていない」かを CSS で示すため、デフォルトでは次のようにする必要があります。
button
{
border-width: 2px;
border-style: outset;
border-color: /*Insert a darker version of your button color here*/
}
次に jQuery で (jQuery で実行できる場合は、そのまま JavaScript でも実行できるため、jQuery を使用したくない場合は注意してください):
$("#btn1").click(function () {
$(this).css("border-style", "inset")
$("#btn2").css("border-style", "outset;");
$("#btn3").css("border-style", "outset;");
$("btnValue").val("btn1IsPressed");
});
$("#btn2").click(function () {
$(this).css("border-style", "inset")
$("#btn1").css("border-style", "outset;");
$("#btn3").css("border-style", "outset;");
$("btnValue").val("btn2IsPressed");
});
$("#btn3").click(function () {
$(this).css("border-style", "inset")
$("#btn1").css("border-style", "outset;");
$("#btn2").css("border-style", "outset;");
$("btnValue").val("btn3IsPressed");
});
あとは、POST (または GET など) の後に値を要求する#btnValue
だけです。通常、どの「ボタン」が押されたかを伝えるのと同じです。
ボタンを「押す」ためにもう少し機能を追加する必要があることをお勧めしますが、要点は理解できたと思います。あなたがする必要があるのは#btnValue
、クリック時に の値を読み取り、他のステートメントとともに if ブランチを使用して、それがすでに押されているかどうかを処理し、それに応じて境界線を切り替えることです (""
値をクリアすることを忘れないでください ( )ボタンの#btnValue
「押し下げ」についての説明なので、ボタンがすべて押されていないかどうかがわかります)。