我想使用原型和scriptaculous來隱藏和顯示div元素,但函數(下)利用原型setStyle屬性不起作用,我是不確定是什麼問題。隱藏並顯示div元素與原型和scriptaculous
<script type="text/javascript" language="javascript">
function bodyOnload() {
$('content1').setStyle({ display: 'none' });
$('content2').setStyle({ display: 'none' });
}
</script>
<script type="text/javascript" language="javascript">
var currentId = null;
Effect.Accordion = function (contentId) {
var slideDown = 0.5;
var slideUp = 0.5;
contentId = $(contentId);
if (currentId != contentId) {
if (currentId == null) {
new Effect.SlideDown(contentId, {duration: slideDown});
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
new Effect.SlideDown(contentId, {duration: slideDown});
}
currentId = contentId;
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
currentId = null;
}
};
</script>
前面的功能被稱爲例如:
<div id="accordion">
<div id="part1">
<div id="nav1" onclick="new Effect.Accordion('content1');">
Post a comment 1
</div>
<div id="content1">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
<div id="part2">
<div id="nav2" onclick="new Effect.Accordion('content2');">
Post a comment 2
</div>
<div id="content2">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
</div>
下面的代碼會發生什麼。
- 在ie和firefox中,它什麼都不做,只是當你點擊調用effect.accordion方法的鏈接時,該方法按預期工作。問題在於原型函數沒有隱藏元素。任何幫助,將不勝感激。
哦,我只是不知道如何使它正確的原型:(現在我知道,謝謝! – maxnk 2008-12-14 08:46:52