問題描述
有沒有辦法在將鼠標懸停在填充了標題"屬性的元素上時禁用瀏覽器工具提示?請注意,我不想刪除標題內(nèi)容.這是請求的代碼:
Is there a way to disable browser tooltip from displaying when hovering over elements that have attribute 'title' populated? Note that I don't want to remove title content. Here is the code are requested:
$(document).ready(function() {
$('a.clickableSticky').cluetip({
splitTitle: '|',
showTitle: false,
titleAttribute: 'description',
activation: 'click',
sticky: true,
arrows: true,
closePosition: 'title'
});
});
在 asp.net 中
and in asp.net
<ItemTemplate>
<a class="clickableSticky" href="#"
title=' <%#((Limit)Container.DataItem).Tip %>'>
<img src="..App_Themesdefaultimagesiconsinformation.png"/>
</a>
</ItemTemplate>
推薦答案
您可以在頁面加載時刪除 title
屬性.
You could remove the title
attribute on page load.
$(document).ready(function() {
$('[title]').removeAttr('title');
});
如果以后需要用到標題,可以將其存儲在元素的jQuery data()
中.
If you need to use the title later, you can store it in the element's jQuery data()
.
$(document).ready(function() {
$('[title]').each(function() {
$this = $(this);
$.data(this, 'title', $this.attr('title'));
$this.removeAttr('title');
});
});
另一種選擇是將 title
屬性的名稱更改為 aTitle
,或者瀏覽器會忽略的其他名稱,然后更新任何 JavaScript 以讀取新屬性名稱而不是 title
.
Another option is to change the name of the title
attribute to aTitle
, or something else that the browser would ignore, and then update any JavaScript to read the new attribute name instead of title
.
更新:
您可以使用的一個有趣的想法是在將鼠標懸停在元素上時懶惰地"刪除標題.當用戶將鼠標懸停在元素上時,您可以將標題值放回去.
An interesting idea you could use is to "lazily" remove the title when hovering over an element. When the user hovers off the element, you can then put the title value back.
這并不像應(yīng)有的那么簡單,因為如果您將 title 屬性設(shè)置為 null
或刪除 title 屬性,IE 不會正確刪除懸停事件上的工具提示.但是,如果您在懸停時將工具提示設(shè)置為空字符串 (""
),它將從包括 Internet Explorer 在內(nèi)的所有瀏覽器中刪除工具提示.
This isn't as straightforward as it should be because IE doesn't correctly remove the tooltip on the hover event if you set the title attribute to null
or remove the title attribute. However, if you set the tooltip to an empty string (""
) on hover, it will remove the tooltip from all browsers including Internet Explorer.
您可以使用我上面提到的方法將title屬性存儲在jQuery的data(...)
方法中,然后將其放回mouseout
.
You can use the method I mentioned above to store the title attribute in jQuery's data(...)
method and then put it back on mouseout
.
$(document).ready(function() {
$('[title]').mouseover(function () {
$this = $(this);
$this.data('title', $this.attr('title'));
// Using null here wouldn't work in IE, but empty string will work just fine.
$this.attr('title', '');
}).mouseout(function () {
$this = $(this);
$this.attr('title', $this.data('title'));
});
});
這篇關(guān)于如何使用 jQuery 在瀏覽器中禁用工具提示?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!