在一个单独的html页面中集成多个功能

时间:2016-07-03 13:29:34

标签: javascript html5

下午好,

我正在尝试在一个html页面中集成多个脚本。不幸的是,我在第49行遇到错误:setInterval(check,1000)。它说'检查'未定义。但是,我有一个函数定义了上面的几行(第28行)命名为' check'?

你能解释一下我错过了什么吗?

非常感谢您的帮助和祝福, 劳伦

<!DOCTYPE html>
<html>
<head>
<title>!Domooslab prototype!</title>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="css/rcswitcher1.min.css">
<link type="text/css" rel="stylesheet" href="css/tabs.css">
<link type="text/css" rel="stylesheet" href="css/mystyle_day.css">
<script type="text/javascript" src="scripts/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="scripts/rcswitcher.min.js"></script>
<script type="text/javascript" src="scripts/modernizr.js"></script>    
<meta name="viewport" content="width=device-width, initial-scale=1">        <!-- est-ce que cette ligne est nécessaire?-->
<script>
/* AJAX request to checker */
$(document).ready(
function check(){
$.ajax({
type: 'POST',
url: 'checker.php',
dataType: 'json',
data: {
counter:$('#message-list').data('counter')
}
}).done(function( response ) {
/* update counter */
//$('#message-list').data('counter',response.current);
/* check if with response we got a new update */
if(response.update==true){
var j = response.news;

$('#message-list').html(response.news);
disBonjour(j);
}
});
});
//Every 1/2 sec check if there is new update
setInterval(check,500);
</script>
<script>
function disBonjour(j){
//console.log("Coucou");

var json=$.parseJSON(j);
var techname = "";
$(json).each(function(i,val){
$.each(val,function(k,v){

if (k=="tech_name")
{
techname = v;
}
else
{
// console.log("Coucou");
console.log("Mon nom est " + techname + " et ma valeur est " + v);
if (v==0)
{
// false

uncheckBox(techname);
}
else
{
// true
checkBox(techname);
}
}

});
});

}
function checkBox(pCtrl)
{
document.getElementById(pCtrl).checked = true;
}
function uncheckBox(pCtrl)
{
document.getElementById(pCtrl).checked = false;
}
</script>
<script>
window.onload = function(){
$('.permissions :checkbox').rcSwitcher({
// reverse: true,
// inputs: true,                    
blobOffset: 0,
onText: 'ON',
offText: 'OFF',
theme: 'light',
// autoFontSize: true,
autoStick: true,
})
// Listen to status changes
.on( 'turnon.rcSwitcher', function( e, data ){

console.log( "New value " + data.$input[0].name + ": " + data.$input[0].checked);
//alert("New value " + data.$input[0].name + ": " + data.$input[0].checked);
})          
.on( 'turnoff.rcSwitcher', function( e, data ){

console.log( "New value " + data.$input[0].name + ": " + data.$input[0].checked);
//alert("New value " + data.$input[0].name + ": " + data.$input[0].checked);
})
;
};
</script>

<script>

$(document).ready(
function() {
setInterval(function() {
var randomnumber = Math.floor(Math.random() * 1000);
$('#show').text(
        'I am getting refreshed every second..! Random Number ==> '
                + randomnumber);
$('#Chambre').html('Coucou');
console.log("Random number : " + randomnumber);

}, 1000);

$('#boxid').click(function() {
if ($(this).is(':checked')) {
$(this).siblings('label').html('checked');
} else {
$(this).siblings('label').html(' not checked');
}
});
});
</script>

</head>
<body>

<h2>Prototype v0.1 (tabs + switch + random)</h2>
<p>Source: <a href="http://www.jqueryrain.com/" target="_blank">http://www.jqueryrain.com/</a></p>
<dl class="accordion">
<dt class="accordion__title">Switches</dt>
<dd class="accordion__content">
<section class="container clear-fix">
<div class="permissions block">
<h4>&larr;Lumieres</h4>         
<label >Chambre 1</label><input type="checkbox" name="ch1" value="ch1" id="chk1">
<label >Chambre 2</label><input type="checkbox" name="ch2" value="ch2" id="chk2">
<label >Chambre 3</label><input type="checkbox" name="ch3" value="ch3" id="chk3">
</div>
<div class="permissions block">
<h4>Sliders</h4>            
<label >Chambre 4</label><input type="checkbox" name="ch4" value="ch4">
<label >Chambre 5</label><input type="checkbox" name="ch5" value="ch5" checked >
</div>
<div class="permissions block">
<h4>Lumieres</h4>           
<label for="Chambre">Chambre 6</label><input type="checkbox" name="ch6" value="ch6">
<label >Chambre 7</label><input type="checkbox" name="ch7" value="ch7" checked >
</div>
</section>
<div id="show" align="center"></div>
<input id="boxid" type="checkbox"><label for="boxid">not checked</label>
</dd>
<dt class="accordion__title">Slider</dt>
<dd class="accordion__content">

</dd>
<dt class="accordion__title">Item 2<img src="image.gif" style="width:30px;height:30px;"></dt>
<dd class="accordion__content">
<p><b>Item 2 content.</b> Ut laoreet augue et neque pretium non sagittis nibh pulvinar. Etiam ornare tincidunt orci quis ultrices. Pellentesque ac sapien ac purus gravida ullamcorper. Duis rhoncus sodales lacus, vitae adipiscing tellus pharetra sed. Praesent bibendum lacus quis metus condimentum ac accumsan orci vulputate. Aenean fringilla massa vitae metus facilisis congue. Morbi placerat eros ac sapien semper pulvinar. Vestibulum facilisis, ligula a molestie venenatis, metus justo ullamcorper ipsum, congue aliquet dolor tortor eu neque. Sed imperdiet, nibh ut vestibulum tempor, nibh dui volutpat lacus, vel gravida magna justo sit amet quam. Quisque tincidunt ligula at nisl imperdiet sagittis. Morbi rutrum tempor arcu, non ultrices sem semper a. Aliquam quis sem mi.</p>.
<p><img src="image.gif"></p>
</dd>
<dt class="accordion__title">Item 3</dt>
<dd class="accordion__content">
<p><b>Item 3 content.</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pellentesque lorem, id suscipit dolor rutrum id. Morbi facilisis porta volutpat. Fusce adipiscing, mauris quis congue tincidunt, sapien purus suscipit odio, quis dictum odio tortor in sem. Ut sit amet libero nec orci mattis fringilla.</p>
<p>Praesent eu ipsum in sapien tincidunt molestie sed ut magna. Nam accumsan dui at orci rhoncus pharetra tincidunt elit ullamcorper. Sed ac mauris ipsum. Nullam imperdiet sapien id purus pretium id aliquam mi ullamcorper.</p>
</dd>  
<dt class="accordion__title">Links</dt>
<dd class="accordion__content">    
<p>Progress pie : <a href="http://www.jqueryrain.com/?eBub464Q" target="_blank"> http://www.jqueryrain.com/?eBub464Q</a></p>
<p>Roundslider : <a href="http://www.jqueryrain.com/?ot4e1H_o" target="_blank"> http://www.jqueryrain.com/?ot4e1H_o</a></p>
<p>Another one : http://www.developerdrive.com/2012/07/creating-a-slider-control-with-the-html5-range-input/</p>
<p>RcSwitcher : <a href="http://www.jqueryrain.com/?1oB4im4M" target="_blank"> http://www.jqueryrain.com/?1oB4im4M</a></p>
<p>Toggle buttons : <a href="https://www.sanwebe.com/2014/02/css3-buttons-examples-with-effects-animations " target="_blank"> https://www.sanwebe.com/2014/02/css3-buttons-examples-with-effects-animations </a></p>
</dd>
</dl>
<script src="scripts/accordion.js"></script>    
</body>    
</html>

0 个答案:

没有答案