は私が.. 私は、チェックボックスの2つのグループのために、このHTMLコードこの問題を持っていますラベル>チェックボックスのテキスト
<label class="checkbox"><input type="checkbox" onClick="toggle_colors(this)" checked><i></i>All Colors</label>
<label class="checkbox"><input type="checkbox" name="colore" checked><i></i>red</label>
<label class="checkbox"><input type="checkbox" name="colore" checked><i></i>yellow</label>
<label class="checkbox"><input type="checkbox" onClick="toggle_brands(this)" checked><i></i>Tutte le Marche</label>
<label class="checkbox"><input type="checkbox" name="brand" checked><i></i>Acer</label>
<label class="checkbox"><input type="checkbox" name="brand" checked><i></i>Asus</label>
をそして私は/トグルすべてすべての選択のために、このJavaScriptを使用します。
function toggle_brands(source) {
checkboxes = document.getElementsByName('brand');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
function toggle_colors(source) {
checkboxes = document.getElementsByName('colore');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
チェックボックスは、私はこのJavaScriptを使用しているかどうかを知るために
ユーザーが、私はAJAXによって、クエリの詳細を送信するために、チェックボックスが選択されているかどうかを知る必要があり、チェックボックスをクリックしてください。.. :
$("[type=checkbox]").change(function() {
if(this.checked) {
alert('checked');
}
else {
alert('unchecked');
}
});
選択したチェックボックスの右側にテキストが必要です。
[OK]親作業で正常に! 私は、クエリを作成するには、このコードを追加しました:
function create_query(){
var query = "SELECT * FROM computers ORDER BY " + ($("#ordine option:selected").val()) + " LIMIT " + ($("#risultati option:selected").val());
$.ajax({
type: "POST",
url: "static/cerca_prodotti.php",
data: "query="+query,
dataType: "html",
success: function(risposta){
$("div#risultati").html(risposta);
},
})
}
$("[type=checkbox]").change(function() {
if(this.checked) {}
else {}
});
$("#ordine").change(function() {
create_query();
});
をしかし、私はチェックボックスが/未チェックチェックした時にクエリを変更する必要があります!
デフォルトではスタイルを指定しないため、チェックボックスのテキストが右側にあるので、スタイル(css)を入力してください。 https://jsfiddle.net/w2uhonqo/ –
@ freedomn-mあなたのセレクターはちょっと離れていて、 '$( '[name =" brand "]')' –
@ArunPJohnyありがとう - あなたが正しい - 彼らは混乱していることをさらに混乱させます。私はとにかく私のコメントを削除します。 –