0

我正在尝试通过使用 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);

这两行……</p>

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>
4

1 回答 1

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上的文档。)

于 2018-10-20T14:19:45.717 回答