asp.net / jQuery select all只能在选项卡中使用

时间:2015-09-02 07:20:52

标签: javascript jquery asp.net

我正在呈现我没有报告时间的不同日期。

如果时间跨度超过1个月,它将在每个月和正确的标签下显示日期。如果日期仅在1个月内,则只会显示日期。

但我的问题是,当日期不在标签栏下时我会选择"选择"所有复选框都不起作用。

这是我的剧本:

$(function () {
    $(".selectAll").on("click", function () {
        if ($(this).is(':checked')) {
            $(this).closest('.panel-default').find("input[name='isoDate']").prop('checked', this.checked);
            $('input[name="isoDate"]').trigger('change');
        } else {
            $(this).closest('.panel-default').find("input[name='isoDate']").prop('checked', false);
            $('input[name="isoDate"]').trigger('change');
        }
    });
});

这就是观点:

@if (ViewBag.MissingDays != null)
{
    int i = 0;
    var months = ((List<DateTime>)ViewBag.MissingDays).GroupBy(x => x.Month);
    IEnumerable<IGrouping<int, DateTime>> groups = months as IList<IGrouping<int, DateTime>> ?? months.ToList();
    foreach (var group in groups)
    {
        i++;
        var month = CultureInfo.CreateSpecificCulture("sv-SE").DateTimeFormat.GetMonthName(group.Key);
        if (groups.Count() > 1)
        {
            <div class="panel-group accordion" id="accordion1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapse_@i">
                                @month
                            </a>
                        </h4>
                    </div>
                    <div id="collapse_@i" class="panel-collapse collapse">
                        <div class="panel-body">
                            <div class="col-md-12">
                                <label>
                                    <input type="checkbox" class="selectAll" name="all"/>
                                    Välj alla.
                                </label>
                                <br/>
                                @foreach (var date in group)
                                {
                                    var isoDate = date.ToString("yyMMdd");
                                    var day = date.ToString("ddd", new CultureInfo("sv-SE")).Substring(0, 2);
                                    <label style="padding-left: 10px">
                                        <input type="checkbox" class="selectedId" name="isoDate" value="@isoDate"/>@day-@isoDate
                                    </label>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
        else
        {
            <div class="col-md-12">
                <label>
                    <input type="checkbox" class="selectAll" name="all" />
                    Välj alla.
                </label>
                @foreach (var date in group)
                {
                    var isoDate = date.ToString("yyMMdd");
                    var day = date.ToString("ddd", new CultureInfo("sv-SE")).Substring(0, 2);
                    <label style="padding-left: 10px">
                        <input type="checkbox" class="selectedId" name="isoDate" value="@isoDate" />@day-@isoDate
                    </label>
                }
            </div>
        }
    }
}

1 个答案:

答案 0 :(得分:1)

假设您只在日期在1个月内时遇到问题,因此不会有任何标签。只需提供日期即可。

请尝试使用以下修改过的脚本:

// define the Person Class
function Person() {}

Person.prototype.walk = function(){
  alert ('I am walking!');
};
Person.prototype.sayHello = function(){
  alert ('hello');
};
// define the Student class
function Student() {
  // Call the parent constructor
  Person.call(this);
}

// inherit Person
Student.prototype = new Person();

// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student;

// replace the sayHello method
Student.prototype.sayHello = function(){
  alert('hi, I am a student');
}

// add sayGoodBye method
Student.prototype.sayGoodBye = function(){
  alert('goodBye');
}

var student1 = new Student();
student1.sayHello();
student1.walk();
student1.sayGoodBye();

// check inheritance
alert(student1 instanceof Person); // true 
alert(student1 instanceof Student); // true