我正在尝试通过使用Javascript小书签自动填充某些字段来加快网页表单填充工作流程。除了填写由Flatpickr控制的几个日期/时间字段外,我已完成所有工作。这是我的书签代码,主要由FormFillerJS.com创建:
var d=document;
function i(a){
return d.getElementById(a)}
function n(a){
return d.getElementsByName(a)[0]}
function e(a){
t='change';
if(window.navigator.userAgent.match(/Trident|MSIEs/g)!=null){
x=d.createEvent('Events');
x.initEvent(t,1,0);}
else{
x=new Event(t);}
a.dispatchEvent(x);}
function v(a,v){
a.value=v;e(a)}
function c(a){
a.checked=true;e(a)}
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
v(n("campus"),"1");
v(i("payroll_addendum_category"),"4");
v(i("payroll_addendum_rate"),"Faculty Rate");
v(i("payroll_addendum_course"),"319");
v(i("payroll_addendum_requested_by"),"John Doe");
v(i("notes"),"My note");
void(0);
这两行...
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
...根本没有填充。我是一个新手,但是我的印象是Flatpickr必须以某种方式调用。有什么方法可以使用JS小书签来完成此操作,还是我不得不使用Flatpickr界面手动选择日期/时间?
如果有帮助,以下是我在这两个字段中看到的消息来源:
<div class="input-label"><input id="start-date" type="hidden" class="required placeholder flatpickr-input" name="start_date" placeholder="Start Date/Time" value="" data-name="my-payroll-create"><input class="required placeholder flatpickr-input flatpickr-mobile" step="any" type="datetime-local" placeholder="Start Date/Time" min="2018-09-18"><input class="required placeholder flatpickr-input form-control input" placeholder="Start Date/Time" type="hidden" readonly="readonly"><div class="placeholder-label">Start Date/Time</div></div></div>
<div><div class="input-label"><input id="end-date" type="hidden" class="required flatpickr-input" name="end_date" placeholder="End Date/Time" value="" data-name="my-payroll-create"><input class="required flatpickr-input flatpickr-mobile placeholder" step="any" type="datetime-local" placeholder="End Date/Time" min="2018-09-18"><input class="required flatpickr-input form-control input" placeholder="End Date/Time" type="hidden" readonly="readonly"><div class="placeholder-label">End Date/Time</div></div></div>
答案 0 :(得分:0)
似乎不是您的台词:
v(i("start-date"),"2018-10-17 11:30");
v(i("end-date"),"2018-10-17 13:30");
您应使用以下类似内容:
i("start-date")._flatpickr.setDate("2018-10-17 11:30", true);
i("end-date")._flatpickr.setDate("2018-10-17 13:30", true);
希望这会有所帮助。
(有关更多详细信息,请参见Flatpickr上的文档。)