*HTML
<div id='board'>
<div>
abc<span class='openCurly bm1'>{</span>
</div>
<div>
'jkl'm<span class='openParen bm2' >(</span>no<span class='closeParen bm2'>)</span>
</div>
<div>
<span class= 'closeCurly bm1'>}</span>
</div>
*JS
$(document).ready(function() {
$("#board").on("mouseenter mouseover", "[class*=bm]", function() {
var className = $(this).attr('class').split(" ")[0];
$("." + className).addClass("curlyHighlight");
});
$("#board").on("mouseleave mouseout", "[class*=bm]", function() {
var className = $(this).attr('class').split(" ")[0];
$("." + className).removeClass("curlyHighlight");
});
});
*CSS
.curlyHighlight {
background-color: red;
font-weight: bold;
}
当我将鼠标悬停在 { 或 } 上时,它会突出显示它们(合作伙伴)。与悬停 ( 或 ) 相同。这是我的小提琴http://jsfiddle.net/yxVd9/10/