如何在单选按钮之间自动切换

时间:2015-08-27 00:38:50

标签: javascript jquery slider

我试图制作一个自动滑动的滑块。 IE浏览器。转到下一张图片。它是一个稍微特殊的滑块。我有单选按钮来控制它所在的图像。

如何让它自动滑动?

            <input type="radio" name="radio-set" checked="checked" id="st-control-1"/>
            <a href="#st-panel-1">A</a>
            <input type="radio" name="radio-set" id="st-control-2"/>
            <a href="#st-panel-2">B</a>
            <input type="radio" name="radio-set" id="st-control-3"/>
            <a href="#st-panel-3">C</a>
            <input type="radio" name="radio-set" id="st-control-4"/>
            <a href="#st-panel-4">D</a>

1 个答案:

答案 0 :(得分:0)

使用setInterval.prop每秒在单选按钮之间自动切换。

看看这个小提琴。

&#13;
&#13;
$(document).ready(function() {
  setInterval(test, 1000);
  var i = 1;

  function test() {
    i = (i % 4) + 1;
    $('#st-control-' + i).prop('checked', true);
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<input type="radio" name="radio-set" checked="checked" id="st-control-1" />
<a href="#st-panel-1">A</a>
<input type="radio" name="radio-set" id="st-control-2" />
<a href="#st-panel-2">B</a>
<input type="radio" name="radio-set" id="st-control-3" />
<a href="#st-panel-3">C</a>
<input type="radio" name="radio-set" id="st-control-4" />
<a href="#st-panel-4">D</a>
&#13;
&#13;
&#13;

相关问题