Javascript 如何将时间值从一个文本框设置为另一个时间选择器?

Javascript 如何将时间值从一个文本框设置为另一个时间选择器?,javascript,jquery,html,wickedpicker,Javascript,Jquery,Html,Wickedpicker,我需要在时间选择器中设置时间值,并将其放入另一个文本框中。 就像我把晚上10:30放在我的文本框里,然后在另一个文本框里点击按钮,这个文本框里有邪恶的时间选择器 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <link rel="stylesheet" href="stylesheets/wickedpicker.css">

我需要在时间选择器中设置时间值,并将其放入另一个文本框中。 就像我把晚上10:30放在我的文本框里,然后在另一个文本框里点击按钮,这个文本框里有邪恶的时间选择器

<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
</script>
<link rel="stylesheet" href="stylesheets/wickedpicker.css">
<script src="src/wickedpicker.js"></script>
<input type="text" class="input" id="time"/><br>
<input type="text" class="input" id="time1"/><br>
<input type="button" value="Show" id="btn"/>
我对date picker也做了同样的操作,它可以工作,所以我认为它可以工作,但它没有用,即使警报不起作用,它说的值未定义。

1)使用
wickedpicker(“时间”)
来获取时间值

2) 在指定时间值之前,将时间转换为24小时格式

$('#time1')。wickedpicker();
$('button')。在('click',function()上{
//从time1获取时间
var t=($('#time1')。wickedpicker('time');
//转换为24小时格式
t=t.replace(“:”,“);
var h=t.分割(“”)[0];
var m=t.分割(“”)[1];
var ampm=t.分割('')[2];
如果(ampm=='PM'){
h=parseInt(h)+12;
}
//将时间设置为时间2
$('\35; time2').wickedpicker({now:h+':'+m});
});

时间1:
时间2:

单击下面的“我”
“代码”包括对wicked picker js的修改,以便更改和更新picker值

/**
*wickedpicker v0.4.1-一个简单的jQuery时间选择器。
*版权所有(c)2015-2016埃里克·加格农-http://github.com/wickedRidge/wickedpicker
*执照:麻省理工学院
* 
*修改为允许更改时间。
*例如:
*var options={now:“12:35”};
*var myPicker=$('.timepicker').wickedpicker(选项);
* 
*myPicker.wickedpicker('setTime',0,“14:00”);//0是计时器选择器的索引。如果只有一个,则使用0
*/
!函数($,窗口,文档){“严格使用”;“函数”!=typeof String.prototype.endsWith&&(String.prototype.endsWith=function(e){return e.length>0&&this.substring(this.length-e.length,this.length)==e});var isMobile=function(){return Android | webOS | iPhone iPhone iPad | iPod |黑莓| IEMobile | Opera Mini/i.test(navigator.userAgent)},todate=new Date=“wickedpicker”,默认值={now:today.getHours()+”:“+today.getMinutes(),二十四:!1,向上箭头:“wickedpicker\uuuuuuuuuuuu控件向上”,向下箭头:“wickedpicker\uuuuuuuu控件向下”,关闭:“wickedpicker\uuuuuuuuuuuuuuuuuuu关闭”,悬停状态:“悬停状态”,标题:“Timepicker”,显示秒:!1,timeSeparator::“,secondsInterval:1,minutesInterval:1,beforeShow:null,afterShow:null,show:null,clearable:!1,closeOnClickOutside:!0,onClickOutside:function(){}};function-Wickedpicker(e,t){this.element=$(e),this.options=$.extend({},defaults,t),this.element.addClass(“hasWickedpicker”),this.element.attr(“onkeypress”,“return假;”,this.element.attr”(“aria showingpicker”、“false”)、this.createPicker()、this.timepicker=$(“.wickedpicker”)、this.up=$(“+this.options.upArrow.split(/\s+/).join(.”)、this.downArrow=$(“+this.options.downArrow.split(/\s+/).join(.”)、this.separator=$(“.wickedpicker控制\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu=$(“.wickedpicker\uuuuuuuuuu controls\uuuuuu control--minutes”)、this.secondsElem=$(“.wickedpicker\uuuuuu controls\uuuuuu control--seconds”)、this.close=$(“+this.options.close.split(/\s+/).join(“.”);var i=this.timeArrayFromString(this.options.now);this.options.now=新日期(today.getFullYear()、today.getMonth()),today.getDate(),i[0],i[1],i[2]),this.selectedHour=this.parseHours(this.options.now.getHours()),this.selectedMin=this.parseCmin(this.options.now.getSeconds()),this.selectedMeridiem=this.parseMeridiem(this.options.now.getHours()),this.setHoverState(),this.attach(e),this.setText(e)}$.extend(Wickedpicker.prototype,{showPicker:function(e){“function”==typeof this.options.beforeShow&&this.options.beforeShow(e,this.timepicker);var t=$(e.offset();if($(e).attr({“aria showingpicker:”true),tabindex:-1})、this.setText(e)、this.showHideMeridiemControl()、this.getText(e)!==this.getTime()){var i=this.getText$,s=/\s\w/.test(i)i.substr(-2,2):null,o=i.replace(/\s\w\w$/,“”)。split(this.options.timeSeparator),n={};n.hours=o[0],n.minutes=o[1],this.options.showSeconds?(n.seconds=o[2],n.meridiem=s:n.meridiem=s,this.setTime(n)}this.timepicker.css({“z-index”:this.element.css(“z-index”)+1,position:“绝对”,left:t.left,top:t+$)[e]).show]函数==typeof this.options.show&&this.options.show(e,this.timepicker),this.handletimeadjusts(e),hideTimepicker:function(e){var t;this.timepicker.hide(),“function”==typeof this.options.afterShow&&this.options.afterShow(e,this.timepicker),function(){var e=$.Deferred();return$('[aria showingpicker=“true”]).attr(“aria showingpicker”,“false”)然后((t=0,void setTimeout(function(){$('aria showingpicker=“false”])attr(“tabindex”,t)},400))),createPicker:function(){if(0===$(.wickedpicker”).length){var e='

+this.options.title+'

  • =“wickedpicker控制-分隔符”>:
  • 00
  • ;此选项。显示秒数和(e+=”
  • 00
  • ),e+=”
  • AM
  • ,(/ul>),this.attachKeyboardEvents()}},showHideMedieMControl:function(){!1===this.options.twentyFour?$(this.meridiemElem).parent().show():$(this.meridiemElem).parent().hide()},showHideSecondsControl:function(){this.options.showSecondselem?$(this.secondsElem).parent().show():$(this.secondsElem).parent().hide()},attach:function(e){var t=this;this.options.clearable&&t.makePickerInputClearable(e),$(e).attr(“tabindex”,0),$(e).on(“单击焦点”,函数(e){$(t.timepicker.is(“:hidden”)&&t.showPicker($(this)),window.lastTimePickerControl=$(this),$(t.hoursElem).focus())};var i=函数(e){if($(t.timepicker.is($(t.timepicker.is(“:visible”){if($(e.target.is(:visible)){(e.is(:visible))(t.meetic))hidder)(window.lastTimePickerControl);else if($(e.target).clo
    $("#time").wickedpicker();
    $("#btn").click(function(){
    var val=$("#time1").val();
    $("#time").wickedpicker("setTime",val);
    $("#time1").wickedpicker("setTime",val);
    alert("selected time is  " + val);
    });
    
    var setTimePicker = function (timeTokens) {
        $('.wickedpicker__controls__control--hours').text(timeTokens[0]);
        $('.wickedpicker__controls__control--minutes').text(timeTokens[1]);
        wickedpicker.data('plugin_wickedpicker').selectedHour = timeTokens[0];
        wickedpicker.data('plugin_wickedpicker').selectedMin = timeTokens[1];
    }