我目前正在開發Codeigniter框架的日曆系統。我希望每次點擊日曆模板中的每天一個單元格時都會顯示一個div。.show()和.hide()命令無法正常工作
的div通過用於循環的PHP創建並從下面的視圖文件數據庫填充:
calendar_view.php
<div class="cal_container">
<?php echo $calendar; ?>
<div class="day_expanded_container">
<?php for ($i = 1; $i<=31; $i++):?>
<div class="day_expanded" id"<?php echo 'd'.$i;?>">
<?php if (isset($calendar_info[$i])):?>
<h2><?php echo $calendar_info[$i]['title'];?></h2>
<p><?php echo $calendar_info[$i]['text']?></p>
<?php else: ?>
<h2>No Data for this Date</h2>
<p>There is currently nothing planned for this Calendar date.</p>
<?php endif; ?>
</div>
<?php endfor;?>
</div>
</div>
以下的jQuery然後施加:
腳本.js
$(document).ready(function(){
var divs = $('div.day_expanded_container > div').get();
var today = $(".today").attr("id");
$(divs).hide().filter('#d' + today).show();
$(".day").click(function() {
var selected = $(this).attr("id");
$(divs).hide().filter('#d' + selected).show();
});
});
但是,在加載頁面divs是全部隱藏,並且點擊根本不顯示。
所有的ID等都是正確的,我無法找到任何東西在CSS將會超越。有什麼顯而易見的,我做錯了嗎?
非常感謝
示例代碼將是比PHP代碼更多的幫助。 –
你有$(「.day」)。click(...)',但是我沒有看到'.day'類的元素。 –
我不明白你爲什麼要使用'.get()',然後繼續傳遞數組回到jQuery工廠。另外,從我通過JS閱讀的內容可以看出,您正在日曆的某個位置創建諸如「id =」1「」的ID。根據http://www.w3.org/TR/html4/types.html#h-6.2這些是無效的ID,可能會導致一些你的麻煩。 – JAAulde