在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 為何運(yùn)行次序不按照程序運(yùn)行?

為何運(yùn)行次序不按照程序運(yùn)行?

<style>
.entered{font-size:36px;width:200px;height:100px;}
#test{border:2px solid red;background:#fdd;width:60px;height:60px;}
</style>

</head>
<body>
    <div id="test">移進(jìn)來</div>    
    <script>
        $("#test").bind("mouseenter mouseout",function(event){
            $(this).toggleClass("entered");
            alert("鼠標(biāo)指針位于(" + event.pageX + "," + event.pageY + ")");
        });    
    </script>

上面這個(gè)簡(jiǎn)單的jquery,
issu1
.entered{font-size:36px;width:200px;height:100px;}
font-size:36px;起作用了 ,為何width:200px;height:100px; 沒有起作用?
issue2
$(this).toggleClass("entered");為何在
alert("鼠標(biāo)指針位于(" + event.pageX + "," + event.pageY + ")");的后面運(yùn)行?
如何讓 $(this).toggleClass("entered"); 運(yùn)行完成后,執(zhí)行alert?

回答
編輯回答
蔚藍(lán)色

issue1: css權(quán)重問題;id選擇器優(yōu)先于class選擇器;
issue2: toggleClass已經(jīng)執(zhí)行,只是alert中斷了樣式的重繪;
你可以在toggleClass中使用function,在function中打印日志,然后會(huì)發(fā)現(xiàn)日志打印成功,然后alert,然后alert關(guān)閉后,樣式變更才生效

2017年3月26日 05:02