Jquery,实时“title”属性更改
Jquery, real time "title" attribute change
我有一个跨度,每秒在工具提示中显示来自服务器的一些数据:
<span class="bata hastip" title="{will change}"></span>
我正在使用工具提示插件来显示工具提示:
$('.hastip').tooltipsy({
offset: [-10, 0],
css: {
'background-color': '#444F54',
'border': '1px solid #888'
}
})
由于我的数据每隔几秒钟就会发生变化,我如何检测这种变化?像这样:
$('.bata').prop('title', datas);
//$('.bata').attr('title', datas) same...
$(document).on('change', '.bata', function(){
//this method doesn't work
});
"你指的是 DOM 突变事件。浏览器对这些事件的支持很差(但正在改进)。jQuery的突变事件插件可能会给你一些方法。
请参阅此相关问题:DOM 属性更改时的触发事件
快捷方式 - 检查此:)
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
支持相当不错,除了IE11+
MDN 的示例用法:
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();
相关文章:
- 如何获取元素's的title属性
- 仅将CSS类添加到那些没有“title”属性的链接中
- 在D3.js中为svg:g元素添加title属性
- 在Oracle Apex 5.0中,无法在侧面导航列表模板中使用title属性
- 工具提示JavaScript在未给出“title”属性时会中断以下表单元素
- 使用属性 “title” 将 html 元素链接到 jQuery.click()
- 在 JS 的单选按钮元素 (HTML) 中使用 title 属性
- Jquery,实时“title”属性更改
- jQuery:删除浏览器生成的 title 属性
- img文件名作为CSS中的title和alt属性
- AngularJS “{{}}” insite title 属性不起作用
- 访问嵌套对象时无法读取未定义的属性“title”
- jQuery 设置 input.value = input.title(或其他输入属性)
- jQuery/JavaScript 查询关于 title 属性
- 如何使用$(this)来动态检索锚点标记的title属性
- 修复了将CSS应用于title属性的脚本的错误
- 如何从tinymce文本区域中删除title属性
- 使用AngularJS将元素文本复制到title属性的干净方法
- 从所有HTML元素中删除属性title
- 属性'title'已经改变了.如何使工具提示理解它