我有一段HTML代碼,當單擊鏈接時,div內容將成爲鏈接的div內容。第一個功能正常工作。這是第二次點擊#hidelink,jQuery似乎沒有迴應。我在這裏錯過了什麼?jQuery .click功能不起作用
<div id="right">
<div id='titletext'><p>||||||||||||||</p></div>
<div id='presentation'></div>
<div class='hidethisdiv'>
<div id ="years">
<h4><a id='resourceslink' href='#resources'>2010 Presentations</a></h4>
</div>
<div id='resources'>
<h4><a id='resourceslink' href='#resources'>2010 Presentations</a></h4>
<p><a id='hidelink' href='#years'>«--back</a></p>
</div>
</div>
</div>
<script type="text/javascript">// <![CDATA[
$('#mainmenu').fadeIn(2000, function() {
// Animation complete.
});
$('#presentation').html($('#years').html());
$(function() {
$("#resourceslink").click(
function() {
$('#presentation').html($('#resources').html());
}
);
$("#hidelink").click(
function(){
$('#presentation').html($('#years').html());
}
);
//just add more divs like resources and a hidelink for new conferences
});
</script>
好像你上次'$(函數(){...'塊嘗試刪除'$(function()'部分,然後運行'$(「resourceslink).click(...)'。如果需要打包,請嘗試'($(function(){ ...})()'希望有幫助,而且'id'不能分配多次,請使用'class'來代替。 – VKen