$("#id").tooltip({
effect: "slide",
tip: '.tooltip'
});
我想刪除此代碼創建的對象。如何在運行時刪除jquery對象?
「的Flowplayer jQuery的工具」插件
這個問題在我的帖子底部描述的答案!
見底部,如果你不想失去你的時間
。
---------- ---------- UPDATE
這應該是這樣的
代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>jQuery tooltip</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://cdn.jquerytools.org/1.1.2/full/jquery.tools.min.js"></script>
<script type="text/javascript">
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
$(document).ready(function() {
$("#_2").tooltip({
effect: "slide",
tip: '.tooltip' ,
position: 'bottom center'
});
});
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
/** The code below is not working as I expect, it doesn't MOVE tooltip **/
var old_id;
//first time - create tooltip
function my_create(id){
$("#"+id).tooltip({
effect: "slide",
tip: '.tooltip',
position: 'bottom center'
});
}
//next times - move tooltip to other element
function my_unlink(id){
$("#"+id).unbind("mouseover");
//todo
}
function my_link(id){
//todo
}
//THE MAIN FUNCTION
function do_tip(new_id){
if(old_id){
my_unlink(old_id);
my_link(new_id);
alert(new_id);
}
else
my_create(new_id);
old_id=new_id;
//new_id.focus();
}
</script>
<style>
.tooltip {
display: none;
background:transparent url(http://flowplayer.org/tools/img/tooltip/black_arrow_bottom.png);
font-size:14px;
height:70px;
width:160px;
padding:25px;
color:#fff;
}
h1 {
width: 400px;
text-align: center;
background-color: yellow;
}
</style>
</head>
<body>
<h1 onclick="do_tip(this.id)" id="_1">John</h1>
<h1 onclick="do_tip(this.id)" id="_2">Mary</h1>
<h1 onclick="do_tip(this.id)" id="_3">Dan</h1>
<h1 onclick="do_tip(this.id)" id="_4">Paul</h1>
<h1 onclick="do_tip(this.id)" id="_5">Kim</h1>
<div class="tooltip">There should be only one tooltip on a page!</div>
</body></html>
。
---------更新2 ----------
這裏的答案
Linking/unlinking jquery object to an element
這個一言難盡的寓意是:
我一直在想這是一個常見的,而不是代碼或特定於插件的問題。我認爲,解決方案應該是簡單的「摧毀舊的工具提示對象,然後創建一個新的,attatched到其他元素」
這是你使用的插件嗎?如果是這樣的話,可能會有一種方法在插件API中將其刪除。 – Fermin 2010-01-22 13:13:48
這是哪個插件?如果不知道插件創建了什麼,就無法回答。 – 2010-01-22 13:24:38
請指定所有必要的html來運行此代碼,以及使用的JavaScript庫和插件 – bjelli 2010-01-22 13:24:43