Bootstrap datepicker:在输入键按下时隐藏日历

时间:2016-11-18 03:22:10

标签: javascript bootstrap-datepicker

如何在输入按键时隐藏bootstrap datepicker日历?我知道它有autoClose选项,但这不是我想要的。

enter image description here

3 个答案:

答案 0 :(得分:1)

这样的事可能会对你有所帮助

$('#date-selected').keydown(function (ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which);
if (keycode == '13') {
    var dp = $('#date-picker').data('datepicker');
    // 1: we manually restore the input date so it's not toggled on/off
    dp.dates.pop(); // idempotent if no dates
    dp.dates.push(dp.viewDate);
    dp.setValue();
    // 2: we move to the next input field & close the picker
    $('input[id!="date-selected"]').first().focus();
    dp.hide();
    }
});

参考: -      https://chezsoi.org/lucas/blog/2014/10/27/en-overriding-the-enter-keydown-behaviour-in-bootstrap-datepicker-js/

答案 1 :(得分:0)

答案 2 :(得分:0)

以下代码为我工作,发布自己的问题答案,以帮助其他

public class PipedPrint implements Runnable {
    PipedOutputStream pos = new PipedOutputStream();
    PipedInputStream pis = new PipedInputStream();
    byte[] abPrinterBytes = null;

    private void mainProcess() throws IOException, PrintException, InterruptedException {
        abPrinterBytes = getBytesFromFile();
        pis.connect(pos);
        Thread randWriter = new Thread(this);
        randWriter.start();
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
        if (defaultService != null) {
            DocPrintJob job = defaultService.createPrintJob();
            DocAttributeSet das = new HashDocAttributeSet();
            Doc doc = new SimpleDoc(pis, flavor, das);
            System.out.println("Main::Fired Print");
            job.print(doc, pras);
            System.out.println("Main::Done Print");
        }
        randWriter.join();
        System.out.println("Main::Join Over");
    }

    private byte[] getBytesFromFile() throws IOException {
        File fFile = new File("C:\\Users\\Wijdan\\Documents\\NetBeansProjects\\demo_print\\src\\demo_print\\pass.txt"); //File to print
        byte[] abFileBytes = new byte[(int) fFile.length()];
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(fFile));
        for (int i = 0; i < abFileBytes.length; i += in .read(abFileBytes, i, (abFileBytes.length - i)));
        return abFileBytes;
    }

    public void run() {
        try {
            Thread.sleep(5000);
            System.out.println("RandWriter started Writing");
            for (int i = 0; i < abPrinterBytes.length; i += 400) {
                pos.write(abPrinterBytes, i, ((i + 400) < abPrinterBytes.length) ? 400 : (abPrinterBytes.length - i));
                System.out.println("Thread:: Wrote bytes. Sleeping....");
                Thread.sleep(500);
            }
            pos.close();
            System.out.println("Thread::Closed pos. Exitting Thread...");
        } catch (Exception ie) {
            ie.printStackTrace();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PipedPrint t1 = new PipedPrint();
        try {
            t1.mainProcess();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}