How can I make a browser display all datalist options when a default value is set?

前端 未结 5 1695
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 17:01

I have an HTML form with a datalist and where the value is set with PHP, like

\">
 

        
5条回答
  •  感情败类
    2020-12-15 17:41

    Another option, based on the proposed solution, that preserves the previous value or the new one chosen.

    // Global variable to store current value
    var oldValue = '';
    // Blank value when click to activate all options
    $('input').on('click', function() {
      oldValue = $(this).val();
      $(this).val('');
    });
    // Restore current value after click
    $('input').on('mouseleave', function() {
      if ($(this).val() == '') {
        $(this).val(oldValue);
      }
    });
    

    https://jsfiddle.net/jpussacq/7Ldbc013/

提交回复
热议问题