Jquery ui jQuery ui工具提示单击获取标题
我正在使用jQueryUI。我可以用标题创建元素并显示标题。但是,单击一下,我想获取标题并填充另一个div(这是因为支持触摸的设备没有工具提示)。我可以获取单击事件,但在单击事件中无法获取标题Jquery ui jQuery ui工具提示单击获取标题,jquery-ui,jquery-ui-tooltip,Jquery Ui,Jquery Ui Tooltip,我正在使用jQueryUI。我可以用标题创建元素并显示标题。但是,单击一下,我想获取标题并填充另一个div(这是因为支持触摸的设备没有工具提示)。我可以获取单击事件,但在单击事件中无法获取标题 $("div").click(function( event ) { // just to prove that we are entering this event $("#preShow").html ( Date() ); // show the title
$("div").click(function( event ) {
// just to prove that we are entering this event
$("#preShow").html ( Date() );
// show the title
var toolTip = this.attributes.title.value;
$("#show").html ( toolTip );
// just to prove that there was no crash
$("#postShow").html ( Date() );
});
我也尝试过使用
var toolTip = $(this).attr ("title");
下面是显示问题的JSFIDLE
如果我创建了一个HTML文件并在Firefox中运行它,并且在click事件的第一行有一个断点,那么同样的代码也可以运行。有人经历过吗 这是因为jQueryUI的工具提示会删除标题并使用它。试着这样做吧
$(document).ready(function () {
$( document ).tooltip( {
track: true,
content: function() {
return $( this ).attr( "title" );
}
});
$('div').click(function(){
$('#show').html($('#' + $(this).attr('aria-describedby')).children().html());
});
});
演示:
如果你有任何问题,请告诉我 老问题,但对于其他寻找这个的人,我建议将当前标题保存在元素的数据属性中,而不是寻找aria descripedby标记。例如,我们在工具提示中使用了一些自定义HTML,这会破坏建议的解决方案。解决它的最简单方法是添加类似于
$(this.data('current-title',element.attr('title'))的内容编码>到内容函数,然后单击查找该数据属性,如果该属性不存在,请改用title。