【发布时间】:2014-02-06 21:19:37
【问题描述】:
我正在尝试遍历一个包含一些复选框的字段,并根据数组中的数据禁用一些复选框。
对于每个框,我想检查复选框的值是否在来自 php.ini 的变量数组中找到。如果是,则禁用该复选框并将一个类添加到父级。
为什么这段代码不起作用? 这是我自己用 jQuery 编写的第一个函数,请见谅。
jQuery(function($) { // wordpress no-conflict hack
var booked = php echo $booked_24; // the php echo syntax is wrong here,
but the editor does not allow me to put in proper php tags.
$('div#acf-booking_times_24 input:checkbox').each(function() {
if ($.inArray(this.value, booked) !== -1) {
$(this).attr('disabled',true);
$(this).parent('label').addClass('unavailable');
}
});
});
【问题讨论】:
-
使用 .prop() 代替 .attr()
-
在调试器中检查是否进入“if”语句