我需要通过链接动态更改具有“名称”属性的变量-以下代码...

       <input type="text" class="datepicker" id="dp1">

       <a href="javascript:;" class="tab" name="1,2">test button</a>




$(document).ready(function(){

    var pickable = { dp1: [4,5,6] };

    $(".tab").click(function () {
        var test = $(this).attr("name").split(",");
        pickable = { dp1:  test  };
    });

    $(".datepicker").each(function() {
        $(this).datepicker({
            beforeShowDay: function(date){
                var day = date.getDay(), days = pickable[this.id];
                return [$.inArray(day, days) > -1, ""];
            },
        });
    });

});​


任何想法为什么这不起作用?

最佳答案

您可以尝试这样的事情

$(document).ready(function(){

var pickable = ["2","3","4","5"];

function closedDays(date){
    var sDate = date.getDay().toString();
    if ($.inArray(sDate, pickable) == -1) return [false,"",""];
    else return [true, ""];
}

$(".tab").click(function () {
   pickable =  $(this).attr("name").split(",");
     closedDays;
});

$(".datepicker").each(function() {
    $(this).datepicker({
        beforeShowDay:  closedDays
    });
});
});​


您可以在这里尝试http://jsfiddle.net/ZKW3b/2/

关于javascript - jQuery的/JavaScript的没有点击值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3820000/

10-11 16:45