我已经尝试搜索我想要完成的内容,但是我还没有找到我要找的东西。
我希望在 Dreamweaver CS6 提供的 Spry Accordion 内容中创建一个 Next 和 Previous 按钮。我搜索了 SpryAccordion.js 并在下面找到了这段代码:
Spry.Widget.Accordion.prototype.openNextPanel = function()
{
return this.openPanel(this.getCurrentPanelIndex() + 1);
};
Spry.Widget.Accordion.prototype.openPreviousPanel = function()
{
return this.openPanel(this.getCurrentPanelIndex() - 1);
};
所以我尝试将“#acc-step-1-next”作为面板 1 中的“下一步”按钮来执行此操作。
<script>
$(document).ready(function(){
$("#acc-step-1-next").click(function(){
Spry.Widget.Accordion.prototype.openNextPanel = function(){
return ('#Accordian1').openPanel(this.getCurrentPanelIndex() + 1);
};
});
});
</script>
我想知道这样做是否会更容易!我将如何应用这个?这行不行?
此外,使用“下一步”按钮,我可以将其设为“.acc-step-next”并普遍使用,而不是单独分配新 ID 吗?
编辑: 抱歉,是的,我错误地阅读了您的答案。我曾尝试搜索 init 属性,但没有成功。
这是 Accordion JS 文件中开始的内容:
(function() { // BeginSpryComponent
if (typeof Spry == "undefined") window.Spry = {}; if (!Spry.Widget) Spry.Widget = {};
Spry.Widget.Accordion = function(element, opts)
{
this.element = this.getElement(element);
this.defaultPanel = 0;
this.hoverClass = "AccordionPanelTabHover";
this.openClass = "AccordionPanelOpen";
this.closedClass = "AccordionPanelClosed";
this.focusedClass = "AccordionFocused";
this.enableAnimation = true;
this.enableKeyboardNavigation = true;
this.currentPanel = null;
this.animator = null;
this.hasFocus = null;
this.previousPanelKeyCode = Spry.Widget.Accordion.KEY_UP;
this.nextPanelKeyCode = Spry.Widget.Accordion.KEY_DOWN;
this.useFixedPanelHeights = false;
this.fixedPanelHeight = 0;
Spry.Widget.Accordion.setOptions(this, opts, true);
if (this.element)
this.attachBehaviors();
};
我在之后添加了这个,但仍然没有成功:
var acc_next = document.getElementById("acc-step-next");
var acc_prev = document.getElementById("acc-step-prev");
$("acc_next").click(function(){
accordion.openNextPanel();
});
$("acc_prev").click(function() {
accordion.openPreviousPanel();
});
最佳答案
我从未使用过 Spry.Widget.Accordion,但我会尝试以下操作。
搜索代码, Accordion 初始化的地方,它应该看起来像这样:
var accordion = new Spry.Widget.Accordion("Accordian1",{});
并在下面添加:
$(".acc-step-next").click(function(){
accordion.openNextPanel();
});
放在一起看起来像这样:
<script type="text/javascript">
$(document).ready(function(){
var accordion = new Spry.Widget.Accordion("Accordian1",{});
// Add a click handler to all buttons with the class 'acc-step-next' (yes you can do that)
$(".acc-step-next").click(function(){
// when the button is clicked, call the openNextPanel method of the accordion instance we saved above
accordion.openNextPanel();
});
});
</script>
关于javascript - Accordion 下一步按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35310493/