我在通知系统上工作,我想把一个数字相当于我的通知数量。 我使用socket.io发送通知。
我已经测试过在函数外面声明var
我的代码是:
<script type="text/javascript">
var socket = io.connect();
var i = 0;
socket.on('libCourtLotChangeServ', function(contrat){
$( "#notifBar" ).append( '<div class="innerNotif" style="width: 96%; height: 30px; text-align: left; border: 1px solid black; background-color: white; padding: 3px;">' + 'Le contrat ' + contrat + ' a été modifié' + '</div>');
function increase(n){
n++;
return n;
}; i = increase(i);
document.getElementById("notificationNumber").innerHTML = i;
})
</script>
答案 0 :(得分:0)
<script type="text/javascript">
var socket = io.connect();
var i = 0;
// Step 1: add a console.log here and make sure its printed in the console when page loads
console.log(i);
socket.on('libCourtLotChangeServ', function(contrat){
//Step 2: add a console.log here and make sure subscriber works
console.log(contrat);
$( "#notifBar" ).append( '<div class="innerNotif" style="width: 96%; height: 30px; text-align: left; border: 1px solid black; background-color: white; padding: 3px;">' + 'Le contrat ' + contrat + ' a été modifié' + '</div>');
//Step 3: Increment i
i++;
//Step 4: Make sure notificationNumber is the ID of the div
//Step 5: use jquery to add value inside `notificationNumber` div
$("#notificationNumber").html(i);
});
</script>