2012-10-31 37 views
1

切換我想點擊一個按鈕(或在我的例子下面鏈接)和內容的2塊之間的切換基本上從顯示的內容編輯內容去。如何在jQuery的

我有下面的代碼snipits:

<style type="text/css"> 
    div.show {display:block;} 
    input.hide {display:none;} 
</style> 

<a href="#">edit</a> <!--not sure what my jquery should look like to do toggling--> 
<div class="show" id="d-01-on">Some content</div> 
<input class="hide" id="d-01-off" name="d-01" value="Some content" /> 

感謝您的幫助。

[見How to Streamline and Compress Repetitive jQuery Code,用於擴展到這個己技巧]

回答

1

這是很容易與jQuery只需添加下面的JS代碼:

$(document).ready(function(){ 
    $('#button').on('click', function() { 
     $('#d-01-on').toggle(); 
     $('#d-01-off').toggle(); 
    }); 
}) 

它將與您當前的標記和CSS代碼工作。

+0

優秀@Skatox。完美的作品。謝謝! –

+0

如果你有一個@Skatox你能看看我的後續問題在http://stackoverflow.com/questions/13159735/how-to-toggle-within-a-content-list-in-jquery?謝謝。 –

+0

我很高興它的工作,會檢查一會兒。 – Skatox

1

顯示和隱藏使用jquery一個元件被如下進行:

HTML:

<div id="d-01">content</div> 

使用Javascript:

$.("#d-01").toggle(); //toggles display so if shown then hides, if hidden then shows; 
$.("#d-01").show(); //shows div 
$.("#d-01").hide(); //hides div