Javascript 禁用所有 jquery datepicker 输入的自动完成功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2765196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:50:19  来源:igfitidea点击:

Disable autocomplete for all jquery datepicker inputs

javascriptjquery

提问by Ibrahim Hussein

I want to disable autocompletefor all inputs using jquery ui datepicker without doing this to every input manually. How could be this done?

我想autocomplete使用 jquery ui datepicker禁用所有输入,而不手动对每个输入执行此操作。这怎么可能?

回答by Luca Filosofi

try this:

尝试这个:

$('.datepicker').on('click', function(e) {
   e.preventDefault();
   $(this).attr("autocomplete", "off");  
});

in anycase you have not mentioned in your question that this is coming from an ajax call!

无论如何,您没有在问题中提到这是来自 ajax 调用!

回答by Makram Saleh

Try this:

尝试这个:

<input type="text" name="field1" value="" autocomplete="off" />

回答by djdd87

Assign a css class to your datepickers, i.e. "datepicker", then do the following:

为您的日期选择器分配一个 css 类,即“datepicker”,然后执行以下操作:

$(".datepicker").attr("autocomplete", "off");

回答by Magno Alberto

This works for me (It was tested on Chrome v70.0.3538.110):

这对我有用(它在 Chrome v70.0.3538.110 上测试过):

            $("#dtpckr([readonly])").datepicker()
            .focus(function() {
                $(this).prop("autocomplete", "off");
                //              return false;
            });

回答by Prashant Belkhede

This works for me perfectly.

这对我来说非常有效。

      $("#autocmpldisablechk").click(function () {

        if (!$(this).is(":checked")) { // enable autocomplete

            $("#autocomplete").autocomplete({
                disabled: false
            });

        }
        else { // disable autocomplete
            $("#autocomplete").autocomplete({
                disabled: true
            });

        }
    });