首页 > 解决方案 > jstree 节点上的 HTML 选择元素立即关闭

问题描述

selectjstree 节点上的元素在单击时立即关闭。input类似地失去焦点,但可以用 JavaScript 解决。但是,它并不能解决select. 下面是一个最小的可重现示例。我该如何解决?

$('#jstree').jstree({
  core: {
    data: [
      {text:`Select <select><option>1</option><option>2</option></select>`},
      {text:`Input <input type="text">`},
    ]
  }
});

$(document).on("click", "input, select", (e) => {
  // e.target.focus(); // fixes the problem only for input
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/jstree.min.js"></script>

<div id="jstree"></div>

标签: javascripthtml-selectjstree

解决方案


推荐阅读