HTML
<div id="radio_btn">
<ul class="tg-list">
<li class="tg-list-item">
<input class="tgl tgl-skewed" id="cb3" type="checkbox"/>
<label class="tgl-btn" data-tg-off="OFF" data-tg-on="ON" for="cb3"></label>
</li>
</ul>
</div>
我想禁用&amp;使用上面的单选按钮启用javascript代码(下面)。
Javascript
window.setInterval(function() {
var elem = document.getElementById('box2');
elem.scrollTop = elem.scrollHeight;
}, 1000);
答案 0 :(得分:0)
没有单选按钮。但要切换间隔,请保存您可以清除的ID
var tId;
$(function() {
$("#cb3").on("click", function() {
if (this.checked) tId = setInterval(
function() {
var elem = document.getElementById('box2');
elem.scrollTop = elem.scrollHeight;
}, 1000);
else clearInterval(tId);
});
});