Bootstrap 工具提示 HTML 焦点可以输入字符

Bootstrap tooltip HTML on focus able to enter characters

参考已经回答的,我想再问一个问题,当我专注于上面有contenteditable 属性的工具提示时,我可以输入上面应该不允许的文字。

我已尝试输入 pointer-events: none,但我仍然可以在 HTML 标签上输入具有 contenteditable 属性.

的任何字符

我该如何解决这个问题?

var tooltipTriggerList = [].slice.call(
  document.querySelectorAll('[data-bs-toggle="tooltip"]')
);
var tooltipList = tooltipTriggerList.map(function(tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl);
});
span[contenteditable] {
  pointer-events: none !important;
}
<head>

  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
  <h6>Bootstrap Icon Tooltip Example</h6>


  <span contenteditable class="fa-solid fa-circle-exclamation mt-4" data-bs-toggle="tooltip" data-bs-html="true" data-bs-trigger="hover focus" title="This is a tooltip with <a href='#'>HTML</a>"></span> This tooltip uses focus and hover. Hover and then
  click the icon.

  <br/>

  <span contenteditable class="fa-solid fa-circle-exclamation mt-4" data-bs-toggle="tooltip" data-bs-html="true" data-bs-trigger="focus" title="This is a tooltip with <a href='#'>HTML</a>"></span> This tooltip uses focus only. You must click the icon
  to view the tooltip.
</body>

Yogi 已经从以下 中回答了这个问题,建议的答案如下:

HTML

<span contenteditable onkeypress="event.preventDefault()" onpaste="event.preventDefault()" class="fa-solid fa-circle-exclamation mt-4" data-bs-toggle="tooltip" data-bs-html="true" data-bs-trigger="hover focus" title="This is a tooltip with <a href='#'>HTML</a>"></span>

或与jQuery

$("[data-bs-toggle=tooltip]").on("keypress paste", function (e) {
    e.preventDefault();
});

感谢所有访问或回答此问题的人