我正在尝试根据对用户名字段的更改来动态更改pikaday日期选择器中允许的月份日期。即使用类似下面的方法禁用每个月的1号以外的所有内容。选择器不起作用。我已经尝试了多种变体。有什么想法吗?
$("#username").on('change', function() {
if(.........){
$('.pika-button :not([value="1"])').prop("disabled", true);
}
});
这是其中一种的内部html,如果有帮助的话:
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="11" data-pika-day="1">1</button>
预先感谢
答案 0 :(得分:0)
$(function() {
$("#username").on('change', '.buttonWrapper', function() {
$('.pika-button:not([data-pika-day=1])').prop('disabled', true);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<body>
<div class="buttonWrapper">
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="1" data-pika-day="1">Month=1, Day=1</button>
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="5" data-pika-day="1">Month=5, Day=5</button>
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="2" data-pika-day="2">Month=2, Day=2</button>
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="3" data-pika-day="4">Month=3, Day=4</button>
<button class="pika-button pika-day" type="button" data-pika-year="2018" data-pika-month="4" data-pika-day="4">Month=4, Day=4</button>
</div>
<input type="text" id="username" />
</body>