jQuery toggle()設定CSS樣式

來源:互聯網
上載者:User

toggle()
切換元素的可見狀態。
如果元素是可見的,切換為隱藏的;如果元素是隱藏的,切換為可見的。
---------------------------------
樣本
切換所有段落的可見狀態。
HTML 程式碼:
<p>Hello</p><p style="display: none">Hello Again</p>
jQuery 代碼:
$("p").toggle()
結果:
<p tyle="display: none">Hello</p><p style="display: block">Hello Again</p>
設定背景圖片,以突出透明度的效果 複製代碼 代碼如下:<head>
<title>toggle()</title>
<style type="text/css">
<!--
body{
background:url(bg.jpg);
margin:20px; padding:0px;
}
img{
border:1px solid #FFFFFF;
}
-->
</style>
<script language="javascript" src="jquery.min.js"></script>
<script language="javascript">
$(function(){
$("img").toggle(
function(oEvent){
$(oEvent.target).css("opacity","0.5");
},
function(oEvent){
$(oEvent.target).css("opacity","1.0");
}
);
});
</script>
</head>
<body>
<img src="test.jpg">
</body>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.