特定のチェックボックスがオンになっていると、URLにテキストを追加します。 私は、すべてのチェックボックスに複数のif文を追加しようと思っていましたが、それはうまくいきませんでした。1つの関数で複数のif文を使用していますか?
$("#button1").on("click", function(){
url = "";
if (auswahl_index1[0].checked) {
url = page + option_0;
}
if (auswahl_index2[0].checked) {
url = page + option_1;
}
window.location.href = url;
});
var auswahl_index1 = document.getElementById('yes1');
var auswahl_index2 = document.getElementById('no1');
var auswahl_index1 = document.getElementById('yes2');
var auswahl_index2 = document.getElementById('no2');
var page = "http://stackoverflow.com";
var url = page;
$("#button1").on("click", function(){
\t url = "";
\t if (auswahl_index1[0].checked) {
\t \t url = page + "test1";
\t }
\t if (auswahl_index2[0].checked) {
\t \t url = page + "test2";
}
if (auswahl_index3[0].checked) {
\t \t url = page + "test3";
\t }
\t if (auswahl_index4[0].checked) {
\t \t url = page + "test4";
}
\t window.location.href = url;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="rdo1" id="yes1"/>
<input type="radio" name="rdo1" id="no1"/>
<input type="radio" name="rdo2" id="yes2"/>
<input type="radio" name="rdo2" id="no2"/>
<button type="button" id="button1">Button</button>
私は2番目の文の「場合、他の」使用している他に何をすべきかと私が見つけたすべて検索するにはしようと試みました。最初のステートメントが偽である場合にのみアクティブになることを意味するので、Hoveverはどちらもうまく動作しませんが、同時に両方ともURLに追加できる必要があります。
申し訳ありませんこれはばかげた質問ですが、私はjqueryに本当に新しいと私は私の問題をgoogleingで何かを見つけることができませんでした。 私の問題についてさらに詳しい情報が必要な場合は、ちょっとお尋ねください。
このhttps://api.jquery.com/checked-selector/ – Tareq
を見てみましょう*」というdid not work "*は適切な問題文ではありません。 [mcve]のための十分なHTMLとコードを提供する。あなたの変数が何を表しているのかわかりません – charlietfl
ありがとうございます、私はコードスニペットとしていくつかのコンテキストを追加しました – KeBom