因為hover不是標准的事件,因此無法直接使用live進行處理,故使用以下方法代替,效果一樣。
. 代碼如下:
$("<SPAN style="COLOR: #0000ff">table tr</SPAN>").live({
<SPAN style="BACKGROUND-COLOR: #99ccff">mouseenter:</SPAN>
function()
{
<SPAN style="COLOR: #008000">//todo</SPAN>
},
<SPAN style="BACKGROUND-COLOR: #99ccff">mouseleave:</SPAN>
function()
{
<SPAN style="COLOR: #008000">//todo</SPAN>
}
});
在循環輸出的<div>中,只針對某個<div>下的內容進行處理的時:可以使用$(this).find()來實現:
. 代碼如下:
<body>
<div class="<SPAN style="COLOR: #0000ff">water</SPAN>">
<div class="<SPAN style="COLOR: #0000ff">action</SPAN>" style="<SPAN style="COLOR: #3366ff">display:none</SPAN>">
<a href="#"><div class="left">{lang user/repick}</div></a>
<a href="#"><div class="right">{lang user/reply}</div></a>
</div>
</div>
<div class="<SPAN style="COLOR: #0000ff">water</SPAN>">
<div class="<SPAN style="COLOR: #0000ff">action</SPAN>" style="<SPAN style="COLOR: #3366ff">display:none</SPAN>">
<a href="#"><div class="left">{lang user/repick}</div></a>
<a href="#"><div class="right">{lang user/reply}</div></a>
</div>
</div>
<div class="<SPAN style="COLOR: #0000ff">water</SPAN>">
<div class="<SPAN style="COLOR: #0000ff">action</SPAN>" style="<SPAN style="COLOR: #3366ff; BACKGROUND-COLOR: #ffffff">display:none</SPAN>">
<a href="#"><div class="left">{lang user/repick}</div></a>
<a href="#"><div class="right">{lang user/reply}</div></a>
</div>
</div>
<div class="<SPAN style="COLOR: #0000ff">water</SPAN>">
<div class="<SPAN style="COLOR: #0000ff">action</SPAN>" style="<SPAN style="COLOR: #3366ff">display:none</SPAN>">
<a href="#"><div class="left">{lang user/repick}</div></a>
<a href="#"><div class="right">{lang user/reply}</div></a>
</div>
</div>
<script type="text/javascript">
$("<SPAN style="COLOR: #0000ff">.water</SPAN>").<SPAN style="COLOR: #800080">hover</SPAN>(
function (){
$(this).<SPAN style="COLOR: #800080">find</SPAN>("<SPAN style="COLOR: #0000ff">.action</SPAN>").show();
},
function (){
$(this).<SPAN style="COLOR: #800080">find</SPAN>("<SPAN style="COLOR: #0000ff">.action</SPAN>").hide();
}
)
</script>
</body>