【发布时间】:2021-06-02 15:24:04
【问题描述】:
我想为selectize 选择焦点值。
此时,我可以单击并删除该值,但我希望 click(focus) 应该选择 selectize 元素的所有值字符串。
您可以在创建新活动时看到 Google 日历的工作原理。
在我这边,如果我单击 time selectize 元素,那么它应该选择所有值字符串,并且可以使用新字符串(如 Google)删除或更新选择。
我的时间选择元素如下。
// php
<div class="select-beast is-hide-selectize-arrow select-event-time-end">
<select name='event_time_end' class='control is-normal select-time' required>
<?php echo TimeHelper::get_times(); ?>
</select>
</div>
// php
function get_times ($default = '19:00', $interval = '+30 minutes') {
$output = '';
$current = strtotime('00:00');
$end = strtotime('23:59');
while ($current <= $end) {
$time = date('H:i', $current);
$sel = ($time == $default) ? ' selected' : '';
$output .= "<option value=\"{$time}\"{$sel}>" . date('h:i A', $current) .'</option>';
$current = strtotime($interval, $current);
}
return $output;
}
...
//jquery
<script>
const $selected_time_start = $('.select-beast select[name="event_time_start"]').selectize({
create: true
});
const selectize_event_start = $selected_time_start[0].selectize;
</script>
我尝试使用焦点事件和select method,如下所示。 但它没有用。
$('.select-beast select[name="event_time_start"]').focus(function() { $(this).select(); } );
【问题讨论】:
标签: javascript php jquery selectize.js