Is it posible to have jQuery UI autocomplete on a

2019-05-15 10:34发布

问题:

In the forum post "How to make jquery autocomplete to work for a contenteditable DIV instead of just INPUT, TEXTAREA fields." we see how to get autocomplete working on a contenteditable div element, however combined with datepicker the datepicker simply does not populate the input field.

As you can see in this jsFiddle demo: http://jsfiddle.net/xvnaA/

Anyone have any wise ideas on how to fix this?

回答1:

Instead of just overriding $.fn.val you could redefine it like this:

(function ($) {
   var original = $.fn.val;
   $.fn.val = function() {
      if ($(this).is('[contenteditable]')) {
         return $.fn.text.apply(this, arguments);
      };
      return original.apply(this, arguments);
   };
})(jQuery);

See http://jsfiddle.net/xvnaA/27/