首页 > 解决方案 > 无论如何要在只读文本字段中添加工具提示

问题描述

我想使用 jquery 在只读字段中添加工具提示。从只读文本框中读取数据并显示为工具提示。我无法在谷歌的任何地方找到它的解决方案

 $(document).ready(function () {
    $('#nextDate').keyup(function () {
        $(this).attr('title', $(this).val())
    })
}) 

html

 <td><input type="text" title="" id="nextdate" class="form-control" readonly=""/></td>

但它不起作用

标签: javascriptjqueryjquery-uijquery-pluginstooltip

解决方案


我正在使用鼠标悬停事件而不是keyup 事件。可能对您有用。

  <td><input type="text" title="hello" id="nextdate" class="form-control" value="2020-10-10" readonly="" onmouseover="myFunction()"/></td>
<script>
function myFunction(){
 document.getElementById('nextdate').setAttribute('title',   document.getElementById('nextdate').value);
}
</script>

推荐阅读