增加DIV数字变量的按钮
Button to increase an DIV number variable
我有以下8张图表
https://jsfiddle.net/BernydotJAr/grwzfjsn/
当然,每个都有不同的DIV ID,我试着在中间放一个按钮,像幻灯片一样在它们之间切换或更改,我可以更改图像,但不能更改DIV。
<div id="chartdiv"></div>
<div id="chartdiv2"></div>
我尝试过Jquery,但我无法显示div中的内容。所以当我单击按钮时,它应该添加一个数字,比如chartdiv&1、chartdiv&2等等,这样我就可以一个接一个地显示。下面是jquery代码(我是从这里得到的:http://www.html5marketplace.com/slideshow/direct/index.html)
<script>
$(window).load(function(){
var pages = $('#container li'), current=0;
var currentPage,nextPage;
var handler=function(){
$('#container .button').unbind('click');
currentPage= pages.eq(current);
if($(this).hasClass('prevButton'))
{
if (current <= 0)
current=pages.length-1;
else
current=current-1;
nextPage = pages.eq(current);
nextPage.css("marginLeft",-604);
nextPage.show();
nextPage.animate({ marginLeft: 0 }, 800,function(){
currentPage.hide();
});
currentPage.animate({ marginLeft: 604 }, 800,function(){
$('#container .button').bind('click',handler);
});
}
else
{
if (current >= pages.length-1)
current=0;
else
current=current+1;
nextPage = pages.eq(current);
nextPage.css("marginLeft",604);
nextPage.show();
nextPage.animate({ marginLeft: 0 }, 800,function(){
});
currentPage.animate({ marginLeft: -604 }, 800,function(){
currentPage.hide();
$('#container .button').bind('click',handler);
});
}
}
$('#container .button').click(handler);
});
</script>
根据您提供的代码和从其他站点获得的代码,div必须位于li元素内部。像这样的
<div id="container">
<ul>
<li>
<div id="chartdiv"></div>
</li>
<li style="display:none;">
<div id="chartdiv2"></div>
</li>
<li style="display:none;">
<div id="chartdiv3"></div>
</li>
</ul>
<span class="button prevButton"></span>
<span class="button nextButton"></span>
</div>
请参阅此处的完整代码
https://jsfiddle.net/grwzfjsn/3/
相关文章:
- Javascript:无法获取变量中的单选按钮值
- 如何将数据从onclick按钮传递到变量
- 将文本框中的值用于按钮窗体操作上的变量
- 需要url导航从DropDown Value onClick按钮传递url变量
- 变量不递增如何I'我喜欢html按钮点击的时候
- 若单击按钮,则更改Javascript中的变量
- HTML 按钮点击函数无法使用 jQuery 变量作为参数
- 使用按钮更改javascript变量
- 按钮的值为2字变量
- JavaScript:如何用变量填充单选按钮值和标签
- 如何从单选按钮中获取多个值,然后将它们分配到单个变量中并在页面上显示
- HTML按钮获胜't更改JS变量
- 单击按钮时填充javascript变量
- 增加DIV数字变量的按钮
- 在两个文件之间共享按钮变量
- 按钮变量范围 - 如何更新父范围中的变量?jQuery.
- 多个 JavaScript 按钮(变量)
- 在jquery追加语句中添加一个按钮变量
- 在 php 中提交单选按钮变量
- 如何用jQuery传递输入值给按钮变量