javascript - 通过 jquery 使用输入标题作为 div 的文本

标签 javascript jquery tooltip

html:

<div id='wrapper'>
<div id='settings'>Settings'</div>
<div id='menu'>
   Jobname <input type=text id='tipjob' title='this text should go into the tooltip' length='20'>
   Appname <input type=text id='tipapp' title='this text should as app text in the tooltip' length='20'>
</div>            
  <div id="build">Builds
      <div id="build-log">Build Log</div>
  </div>
  <div id="content">Content
      <div id="tooltips">Tooltip</div>
  </div>
<div id='footer'>Footer</div>
</div>

JavaScript:

$(document).ready(function(){
$('#tipjob').bind('mouseenter', function() {
    $('#tooltips').fadeIn();
});
$('#tipjob').bind('mouseleave', function() {
    $('#tooltips').fadeOut();
});
});

也可以在 jsfiddle 上查看 css。

http://jsfiddle.net/yZZDd/433/

在上面的示例(不起作用)中,我希望当一个人将鼠标悬停在输入字段上时能够淡入/淡出一些文本。文本应该进入 div“工具提示”,它现在隐藏在 css 中(也许不是最好的方法)

除了默认的 jquery 之外,我不需要任何其他工具提示库(因为关于工具提示,我认为不需要它)

所以我假设我在每个输入字段中使用 mouseenter/mouseleave,然后设置淡入淡出,但我不知道如何以某种方式将输入字段中的文本放入其中。

由于我从 1 个输入字段开始,我可以只显示和隐藏 div,但这成为第二个输入字段的问题:)

希望我解释正确。这里是第一个计时器。

最佳答案

试试这个 - DEMO

$(document).ready(function(){
    $('input').on({
        mouseenter: function() {
            $('#tooltips').text( $(this).prop("title") ).stop(1, 1).fadeIn();
        },
        mouseleave: function() {
            $('#tooltips').fadeOut();
        }
    });
});

关于javascript - 通过 jquery 使用输入标题作为 div 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14032510/

相关文章:

javascript - 如何通过jQuery onblur提交表单

javascript - 全身背景的定时背景变化

php - iPad 上 Safari 中的用户超时

javascript - 将 javascript 重写为 jquery 以实现页面上的多个表单

javascript - 允许 <a> 标签标题属性中包含 html

javascript - 丑陋的 AngularJS

javascript - 如何有条件地制作 "sticky"页脚?

jquery - 如何制作qtip2逐步引导,重新打开工具提示?

drop-down-menu - 下拉列表中的工具提示

jquery - 覆盖页面但排除特定 div - jQuery Impromptu