jquery - turning “autocomplete” to off for all forms (even ones not loaded yet)

前端 未结 4 1927
时光说笑
时光说笑 2020-12-16 12:31

So, I\'ve got this code:

$(document).ready(function(){
    $(\'form\').attr(\'autocomplete\', \'off\');
});

It works great for all forms al

4条回答
  •  执念已碎
    2020-12-16 13:06

    The live event is now deprecated, you should us the on event instead. This will attach to every input in the DOM no matter if it's created yet or not. It will then add the autocomplete="off" attribute to that input.

    $(document).ready(function() {
      $(document).on('focus', ':input', function() {
        $(this).attr('autocomplete', 'off');
      });
    });
    

提交回复
热议问题