學到插件 自己也倒弄出來一個。
效果圖如下:
代碼如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>無標題頁</title> <style type="text/css"> #conBox{ position:absolute; width:200px;padding:5px;display:none;background:#666;z-index:999;border-radius:5px;} </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> </head> <body> <span class="ll" title="123">你好</span> <a title="123" href="#">四大發送</a> <a title="123" href="#">12331</a> <a title="123" href="#">12331</a> <a title="123" href="#">12331</a> <a title="123" href="#">12331</a> <a title="123" class="ll" href="#">1的爽膚水</a> <a title="123" href="#">1撒旦法1</a> <a title="123" href="#">12撒旦法1</a><a title="123" href="#">12331</a> <a title="123" href="#">12331</a> <a title="123" href="#">12331</a> <a title="123" class="ll" href="#">12331</a> <div></div> <script language="javascript" type="text/javascript"> $(function(){ //插件主題 $.fn.extend({ showTitle:function(){ $('<div id="conBox"></div>').appendTo('body'); var d=$("#conBox"); this.bind({ mouseover:function(){ if(!$("#conBox")){ $('<div id="conBox"></div>').appendTo('body'); }else{ d=$("#conBox"); } var of=$(this).offset(); var title=$(this).attr("title"); //定義位置 d.css({top:of.top+$(this).height()+"px",left:$(this).width()/2+of.left+"px"}).text($(this).attr("title")); //顯示 d.fadeIn(); }, mouseout:function(){ //鼠標一走隱藏 d.fadeOut(); } }); } }); //調用 $(".ll").showTitle(); }); </script> </body> </html> [Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]