check box to activate/deactivate
I have the following code. I want to make a check box that will activate this code when checked and deactivates the code when unchecked. can someone show me how?
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('record_count.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
<body>
<div id="load_tweets"> </div>
</body>
</script>
开发者_如何转开发
var refresh = function() { $('#load_tweets').load('record_count.php').fadeIn("slow"); };
refresh();
var auto_refresh = null;
$('#the-checkbox').change(function(ev) {
if (auto_refresh) clearInterval(auto_refresh);
auto_refresh = $(this).is(':checked') ? setInterval(refresh, 10000) : null;
});
setInterval(function () {
if ( $("#myCheckbox").is(":checked") ) {
$('#load_tweets').load('record_count.php').fadeIn("slow");
}
}, 10000); // refresh every 10000 milliseconds
精彩评论