我正在嘗試爲每個檢查/取消選中這些複選框的網站提出請求。 但是,這裏的問題在於我包含在我的網頁中的事件不起作用;當我檢查/取消選中沒有任何反應時。如何處理來自jQuery腳本的事件?
這是我的HTML代碼:
<form method="get" style="display:inline;" class="ListeAlertes"><input type="checkbox" name="fixee" value="true" style="margin-left:40px;margin-right:3px;" @ViewBag.Fixee /> Alertes fixées<input type="checkbox" name="nonFixee" value="true" style="margin-left:10px;margin-right:3px;" @ViewBag.NonFixee /> Alertes non-fixées</form>
jQuery代碼:
$(".ListeAlertes input[type='checkbox']").change(function() {
var form = $(".ListeAlertes").serialize();
if (($("input[name='fixee']:checked") && $("input[name='nonFixee']:checked")) || ($("input[name='fixee']:unchecked") && $("input[name='nonFixee']:unchecked"))) {
$.get("~/Alertes/Index?fixee=true&nonFixee=true");
}
if ($("input[name='fixee']:checked") && $("input[name='nonFixee']:unchecked")) {
$.get("~/Alertes/Index?fixee=true&nonFixee=false");
}
if ($("input[name='fixee']:unchecked") && $("input[name='nonFixee']:checked")) {
$.get("~/Alertes/Index?fixee=false&nonFixee=true");
}
});
任何高招嗎?
我需要檢查,如果兩個複選框也選中或取消選中。你能不能更新我寫的內容來更好地理解你在這裏做什麼? – user3264174
在你提供的小提琴中:[jsfiddle](http://jsfiddle.net/eKa8S)更正警報的拼寫。現在警報即將到來。接下來,你不能直接檢查「取消」。可以檢查'checked'的.attr()爲false。進行這些更改並且您的代碼將會正常。 – Jobin
我試圖讓它更好的編碼,我有這個:http://jsfiddle.net/eKa8S/4/警告框還沒有出現。 – user3264174