【问题标题】:Changing Radio Select更改电台选择
【发布时间】:2014-12-19 22:15:38
【问题描述】:

好的,所以我有一个单选按钮幻灯片,我用一些简单的 CSS 和 HTML 制作,但现在我需要它每 3 秒更改一次,但我仍然希望它能够通过选中单选按钮来更改。 ..

这是我的 Css 代码

.photo {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 800px;
    height: 300px;
    opacity: 0;
    transition: all 1s;
    z-index: -1;
}

.container {
    position: relative;
    width: 800px;
    height: 300px;
    overflow: hidden;
    margin: 10px;
    text-align: center;

}



input[type=radio]:checked ~ .photo {
    transition: all 1s;
        opacity: 100;
}

.photo1 {
        position: absolute;
        bottom: 0;
    right: 52%;
}
.photo2 {
        position: absolute;
        bottom: 0;
    right: 50%;

}
.photo3 {
        position: absolute;
        bottom: 0;
    right: 48%;
}

这是我的html代码

<table>
<tr>
<td>
<form class="container">
<table>
</tr>
<td>
<input type="radio" name="photo" class="photo1" checked="true">
<img src="Footloose.png" class="photo">
</td>

<td>
<input type="radio" name="photo" class="photo2" >
<img src="Shrek.jpg" class="photo">
</td>

<td>
<input type="radio" name="photo" class="photo3" >
<img src="LegallyBlond.jpg" class="photo">
</td>
</form>
</tr>
</table>

我是 Java 和 Javascript 的新手,当我尝试时,它不起作用。提前感谢您的帮助!

【问题讨论】:

  • java和javascript相距甚远
  • 你的问题不清楚

标签: html css button timer radio


【解决方案1】:

您可以尝试使用 setInterval() 方法,使用以下代码:

<script>
function setchecked(){
       var photos = document.getElementsByName("photo"),
                i = 0;
       for (i = 0; i < 3; i++)
       {
            if(photos[i].checked == true)
            {
                photos[i].checked = false;
                i = i+1==3 ? 0 : i+1;
                photos[i].checked = true;
                break;
            }
        }
    }

    setInterval(setchecked, 3000);
</script>

【讨论】:

    猜你喜欢
    • 2011-09-25
    • 1970-01-01
    • 2016-09-28
    • 2011-07-27
    • 2013-03-03
    • 1970-01-01
    • 2016-02-26
    • 2016-04-01
    • 2014-01-12
    相关资源
    最近更新 更多