我正嘗試使用jQuery在表格單元格上創建簡單的工具提示。
我寫了這個代碼:表格單元格上的jQuery工具提示
<script type="text/javascript">
$(function() {
$(".test").bind("mouseenter", function (e) {
$("#ToolTipDIv").offset({ left: e.pageX, top: e.pageY });
$("#ToolTipDIv").show("slow");
});
$(".test").bind("mouseleave", function (e) {
$("#ToolTipDIv").hide("slow");
});
});
</script>
<div id="ToolTipDIv" style="background-color: Yellow; display: none; width: 20%;">
This is a text
</div>
<table class="style1" border="1">
<tr>
<td class="test">
1
</td>
<td class="test">
6
</td>
</tr>
<tr>
<td class="test">
2
</td>
<td class="test">
7
</td>
</tr>
</table>
但預期這是行不通的。當我將鼠標移過單元格Tooltip Div關閉並打開數次。
例如,我想查看第三個單元格的工具提示我將鼠標指針放在第一個和第二個單元格上以到達第三個單元格.jQuery工具提示將顯示並隱藏3次。
jsfiddle link
你能編輯我的小提琴嗎? http://jsfiddle.net/DmnMQ/2/ – Shahin
根據定義,你的代碼將不起作用。當鼠標懸停在某物上時,你希望工具提示顯示出來,當你的鼠標離開時,工具提示會消失,但是,一旦工具提示彈出到鼠標位置,就意味着它會離開原來的位置。我創建了一個小提琴http://jsfiddle.net/DmnMQ/12/,以我要做的事情爲例,但如果無論如何我會嘗試使用現有的代碼來獲取jQuery工具提示。 – kasdega
非常感謝:) :)] – Shahin