我在MVC中有15个复选框,我想在检查其中任何五个时填写下拉列表。在JavaScript的帮助下...请帮助我,我是编程的新手,所以我无法管理它。如果你可以帮助我至少javascript它是非常有帮助的。
$(document).ready(function () {
$("#timeslotee").prop("disabled", true);
$("#Day").change(function () {
if ($("#Country").val() != "Select") {
var DocOptionss = {};
DocOptionss.url = "/Sample/timeslot";
DocOptionss.type = "POST";
DocOptionss.data = JSON.stringify({ dayy: $("#Day").val(), docname: $("#State").val() });
DocOptionss.datatype = "json";
DocOptionss.contentType = "application/json";
DocOptionss.success = function (StatesListd) {
$("#timeslotee").empty();
for (var i = 0; i < StatesListd.length; i++) {
$("#timeslotee").append("<option>" + StatesListd[i] + "</option>");
}
$("#timeslotee").prop("disabled", false);
};
DocOptionss.error = function () { alert("Error in Selecting A Day!!"); };
$.ajax(DocOptionss);
}
else {
$("#timeslotee").empty();
$("#timeslotee").prop("disabled", true);
}
});
});
public JsonResult Days(string docname)
{
var dd = db.USERs.FirstOrDefault(s => s.Full_name == docname);
List<string> StatesListw = new List<string>();
if (dd.DOCTOR.DOCTOR_DAYS.Monday)
{
StatesListw.Add("Monday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Tuesday)
{
StatesListw.Add("Tuesday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Wednesday)
{
StatesListw.Add("Wednesday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Thursday)
{
StatesListw.Add("Thursday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Friday)
{
StatesListw.Add("Friday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Saturday)
{
StatesListw.Add("Saturday");
}
if (dd.DOCTOR.DOCTOR_DAYS.Sunday)
{
StatesListw.Add("Sunday");
}
return Json(StatesListw);
}
答案 0 :(得分:0)
您使用的是jQuery吗?如果是这样,这应该有效:
var $checkboxes = $('input:checkbox');
$checkboxes.change(function(){
var numChecked = 0;
$checkboxes.each(function(index, element){
if(element.checked){
numChecked++;
}
});
if(numChecked >= 5){
//do something
}
});