我有導航菜單使用圖像,我希望如果用戶單擊菜單,然後更改圖像。假設我的圖片菜單是「about-us-our-mission.jpg」,那麼一旦用戶點擊此按鈕,它將變成「about-us-our-mission-roll.jpg」,所以如果用戶點擊另一個按鈕像「about-us-our-pride.jpg」那麼它應該變成「about-us-our-pride-roll.jpg」,並將另一個按鈕放回到先前的圖像中,例如「about-us-our-mission-roll.jpg 「into」about-us-our-mission.jpg「jquery更改圖像菜單選擇時
有可能嗎?
在此先感謝
Tirso的
這裏是我的HTML菜單
<ul class="about-nav" id="content-linkwrap">
<li><a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('our-mission','','<? echo base_url() ?>images/about-us-our-mission-roll.jpg',1)" class="hrefmenu" id="mission-href"><img src="<?php echo base_url() ?>images/about-us-our-mission.jpg" id="our-mission"/></a></li>
<li><a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('our-pride','','<? echo base_url() ?>images/about-us-our-pride-roll.jpg',1)" class="hrefmenu" id="pride-href"><img src="<?php echo base_url() ?>images/about-us-our-pride.jpg" id="our-pride"/></a></li>
<li><a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('our-business','','<? echo base_url() ?>images/about-us-our-philosopy-roll.jpg',1)" class="hrefmenu" id="business-href"><img src="<?php echo base_url() ?>images/about-us-our-philosopy.jpg" id="our-business"/></a></li>
<li><a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('our-family','','<? echo base_url() ?>images/about-us-our-family-roll.jpg',1)" class="hrefmenu" id="family-href"><img src="<?php echo base_url() ?>images/about-us-our-family.jpg" id="our-family"/></a></li>
<li><a href="javascript:void(0)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('our-profile','','<? echo base_url() ?>images/about-us-our-profile-roll.jpg',1)" class="hrefmenu" id="profile-href"><img src="<?php echo base_url() ?>images/about-us-our-profile.jpg" id="our-profile"/></a></li>
</ul>
這裏是我的JavaScript這將改變內容
$("#content-linkwrap .hrefmenu").click(function(){
$clicked = $(this);
// if the button is not already "transformed" AND is not animated
// each button div MUST have a "xx-button" and the target div must have an id "xx"
var idToLoad = $clicked.attr("id").split('-');
//var img = $(this).parent().find("#our-"+idToLoad[0]).attr("src");
//we search trough the content for the visible div and we fade it out
$("#description").children().filter(":visible").fadeOut("fast", function(){
//once the fade out is completed, we start to fade in the right div
$(this).parent().find("#"+idToLoad[0]).fadeIn();
})
});
你有一個示例代碼? 謝謝 – tirso 2009-11-29 01:10:25
我可以在幾天內爲你提供一些東西,但是如果你花了一兩個小時的時間用一些jQuery教程,你可能會學到更多東西。學習語言並不難:-) – jkndrkn 2009-11-29 01:45:54
hi jkndrkn 我已經解決了! 感謝您的挑戰 – tirso 2009-11-29 15:34:04