ILi*_*les 3 jquery jquery-ui jquery-ui-tooltip
我正在使用JQUERY和JQUERY UI来更改一小段文本的标题值.当页面首次加载时,工具提示工作正常,并显示我的"点击展开"工具提示.当用户点击"more ..."或"less ..."文本时,它应该触发点击功能(它会这样做); 切换博客文章的可见性(它的作用); 将文本从更多切换到更少,反之亦然(它确实如此); 然后更新按钮的标题,以便工具提示显示新文本(它在Chrome中显示更新).但是,工具提示永远不会改变,即使标题显示"Collapse Post" - 工具提示仍然显示"Click for more".
如何以JQUERY UI工具提示看到更新并在鼠标悬停时正确报告新值的方式动态更新我的标题?
/*
*
* @DocumentReady
*/
$(window).ready(function(){ //Checks if the document is ready
/*
*
*
*/
$(".moreButtonClass").click(function(){ //Handles the button click
// just leaves the number and appends to make the div ID
var postID = "#post" + this.id.replace(/[^\d]/g, "");
var moreButton = "#moreButton" + this.id.replace(/[^\d]/g, "");
$(postID).toggle(); // Toggle visibility
if($(postID).is(":visible")) {
$(moreButton).text("less...");
$(moreButton).attr("title", "Collapse Post");
} else {
$(moreButton).text("more...");
$(moreButton).attr("title", "Show Post");
}
}); //Close the function
/*
*
*
*/
$( "#tabs" ).tabs({
beforeLoad: function( event, ui ) {
ui.jqXHR.error(function() {
ui.panel.html(
"Couldn't load this tab. We'll try to fix this as soon as possible. ");
});
}
}); // Close the function
/*
*
*/
$(function() {
$( document ).tooltip({track: true}); // Allow JQUERY to handle tooltips
}); // Close the function
}); // Close the Document Ready Function
Run Code Online (Sandbox Code Playgroud)
Ric*_*ard 10
你不能使用
$(moreButton).attr("title", "Show Post");
Run Code Online (Sandbox Code Playgroud)
因为工具提示由jQuery UI初始化.而是使用这个:
$(moreButton).tooltip( "option", "content", "Show Post - test" );
Run Code Online (Sandbox Code Playgroud)
RTM:http://api.jqueryui.com/tooltip/#option-content
小智 5
我将 Jquery 与 bootstrap 一起使用,但这些都不起作用。我必须这样做:
$("#myelement").attr("data-original-title", "New title/message" );
Run Code Online (Sandbox Code Playgroud)
这是在使用 ajax 的动态加载模式内部工作的 - 并且原始页面元素已更改,因此看起来很可靠。