gpt4 book ai didi

javascript - 如何以编程方式打开时间选择器

转载 作者:行者123 更新时间:2023-11-30 20:40:29 25 4
gpt4 key购买 nike

我有一个 MaterializeCSS时间选择器元素。我需要将它链接到隐藏的输入字段,并且 (1) 通过单击按钮以编程方式触发时钟对话框的打开。另外,(2) 我需要拦截时间选择事件。

这是一个示例代码。

<html>
<head>
<!-- jQuery -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<!-- Compiled and minified MaterializeCSS JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
</head>
<body>

<input type="hidden" id="mytimepickerelement" class="timepicker" class="validate">
<a class="waves-effect waves-light btn timepicker" onclick="showtimepicker();">Set time</a>

<script type="text/javascript">
function showtimepicker() {
// (1) TODO ON $('#mytimepickerelement')
}
function initializetimepicker() {
$('.timepicker').pickatime({
default: '0:00',
fromnow: 0,
twelvehour: false,
donetext: 'OK',
cleartext: 'Clear',
canceltext: 'Cancel',
autoclose: false,
ampmclickable: false,
aftershow: function(){},
// (2) SOMETHING ELSE TODO TO INTERCEPT TIME SELECTION/MODAL CLOSURE EVENT
});
}
$(document.ready(intializetimepicker));
</script>
</body>
</html>

如何解决 (1) 和 (2) 并使按钮正常工作?

最佳答案

关于第一次我觉得有点奇怪。我模拟了点击时间选择器但没有任何反应。所以我将它延迟了约 1 毫秒,它起作用了……我知道这是一个奇怪的解决方案,但它仍然是解决方案。

示例 HTML:

<a onclick="ope();">adas</a>

<div class="row">
<div class="input-field col s12">
<label for="timepicker_ampm_dark">Time am/pm ( dark theme )</label>
<input id="timepicker_ampm_dark" class="timepicker" type="time"/>
</div>
</div>

Js/jq:

//Time Picker:
$('.timepicker').pickatime({
default: 'now',
twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
donetext: 'OK',
autoclose: false,
vibrate: true // vibrate the device when dragging clock hand
});

function ope(){
setTimeout(function(){
$('label').click();
},1);
}

关于javascript - 如何以编程方式打开时间选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49323380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com