Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可编辑选择_Javascript_Jquery - Fatal编程技术网

Javascript 可编辑选择

Javascript 可编辑选择,javascript,jquery,Javascript,Jquery,以下是我的HTML代码: <div class="editable-select-holder"> <input type="text" name="position" id="position" value="${userInfoForm.position}"> <button type="button" class="editable-select-expander"></button> <ul class="ed

以下是我的HTML代码:

<div class="editable-select-holder">
    <input type="text" name="position" id="position" value="${userInfoForm.position}">
    <button type="button" class="editable-select-expander"></button>
    <ul class="editable-select-options">
        <c:forEach var="position" items="${positions}">
            <li>${position.description}</li>
        </c:forEach>
    </ul>
</div>
当我点击按钮或关注输入时,我想查看和列出。我上面提供的代码只在单击按钮时起作用。在焦点事件上我也需要同样的逻辑。有什么建议吗

像这样改变了,但仍然不能正常工作

 $(document).on("click",'.editable-select-holder', function() {
                var $holder = $(this);
                $holder.on('click','.editable-select-expander', function() {
                    $holder.toggleClass('editable-select-expanded');
                });

                $holder.on('click', 'li', function() {
                    var $t = $(this);

                    $holder.removeClass('editable-select-expanded');

                    $holder.find('input').val($t.text());
                });

                $holder.on('focus', 'input', function() {
                    $holder.addClass('editable-select-expanded');
                });
            });

我希望你能使用这个代码

  $( your input box id or class ).focusin(function() {
  //your logic here
  });

tabindex
属性添加到所有
li
s以使其可聚焦。
  $( your input box id or class ).focusin(function() {
  //your logic here
  });