jquery用onmouseout和onmouseover怎么改变span或div中的文字的颜色,大小,粗体,字

2025-03-07 06:28:34
推荐回答(1个)
回答1:

首先,jQuery中的方法是mouseout和mouseover

onmouseout/onmouseover是javascript的方法

js方法:

var oBox = document.getElementById("box");
oBox.onmouseover = function(){
    var oEvent = ev || event;//兼容处理
    var oFrom = oEvent.fromElement || oEvent.relatedTarget;//兼容处理
    //如果在里面则返回
    if(oFrom && oBox.contains(oFrom)){
        return;    
    }
    //移入时触发
    oBox.style.color="red";//颜色设置
    oBox.style.width="100px";//宽度
    oBox.style.height="100px"; //高度
    oBox.style.font="italic bold 12px arial,serif";//字体
}
oBox.onmouseout = function(){
     var oEvent = ev || event; //处理兼容
    var oTo = oEvent.toElement || oEvent.relatedTarget; //处理兼容
    //如果在里面则返回
    if(oTo && oBox.contains(oTo)){
        return;
    }
    //移出时触发
    oBox.style.color="black";//颜色设置
    oBox.style.width="50px";//宽度
    oBox.style.height="50px"; //高度
    oBox.style.font="italic bold 12px arial,serif";//字体  
}


jQuery方法

var price_tip_pop = null;
$('#box').mouseout(function(){
    //移出时触发
    $(this).css({"color":"black","width":"50px","height":"50px","font":"italic bold 12px arial"});
}).mouseover(function(){
    //移入时触发
    $(this).css({"color":"red","width":"100px","height":"100px","font":"italic bold 12px arial"});
});