-1
工作我有這個jQuery代碼的一個問題:jQuery代碼頁不工作,但在控制檯
$("#shout-msg").val('').attr('disabled', false);
$("#shout-send").attr('disabled', false);
它適用於谷歌瀏覽器的控制檯,但它不會對JavaScript文件的工作。這是整個代碼。
var shoutbox = {
opened: false,
last: false,
interval: 0,
open: function() {
$("#shoutbox #open").hide('blind');
$("#shoutbox #main").show('blind');
shoutbox.opened = true;
$.cookie('shoutbox', 'aberta', { expires: 30, path: '/' });
shoutbox.update(1);
},
close: function() {
$("#shoutbox #main").hide('blind');
$("#shoutbox #open").show('blind');
shoutbox.opened = false;
$.cookie('shoutbox', 'fechada', { expires: 30, path: '/' });
},
send: function() {
var msg = $("#shout-msg").val();
if(shoutbox.opened == true && msg != '') {
$("#shout-msg, #shout-send").attr('disabled', true).removeClass('red');
$.ajax({
type: 'POST',
data: {'msg': msg},
dataType:"JSON",
url: '/lib/shout_enviar.php',
success: function(html) {
if(html.concluido == true) {
$("#shout-msg").val('').attr('disabled', false);
$("#shout-send").attr('disabled', false);
}
clearTimeout(shoutbox.interval);
shoutbox.update(1);
}
});
}
},
update: function(a) {
if(shoutbox.opened == true) {
if(a == 0) { shoutbox.last = 0; }
$.ajax({
type:'GET',
dataType:'JSON',
url: '/lib/shout_update.php?last='+shoutbox.last,
success: function(html) {
i = 0;
while(i < html.length) {
var dados = html[i];
if(dados['id'] > shoutbox.last) {
shoutbox.add(dados['id'], dados['nick'], dados['msg']);
shoutbox.last = dados['id'];
}
i++;
}
shoutbox.interval = setTimeout(function() {shoutbox.update(1);}, 2500);
}
});
}
},
add: function(id, nick, msg) {
var msg_add = '';
msg_add += '<div id="msg" class="msg-shout" rel="'+id+'"><div id="info"><div style="float:left;width:165px;">';
msg_add += '<b>'+nick+' enviou:</b><br />';
msg_add += msg + '</div>';
msg_add += '<div id="img" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='+nick+'&action=std&direction=4&head_direction=4&gesture=sml&size=s);"></div>';
msg_add += '<div id="clear"></div></div></div>';
$("#shoutbox #messages #scroll").prepend(msg_add);
},
start: function() {
if($.cookie('shoutbox') == 'aberta') {
shoutbox.opened = true;
}
shoutbox.last = $("#shoutbox #msg:first-child").attr('rel');
shoutbox.update(0);
},
}
很抱歉,如果我的英語不好,我來自巴西。
謝謝!
@dystroy #scroll在裏面#messages裏面#shoutbox –
使用'$(function(){/ * Code here * /})'。 – gdoron
@FNXHenry如果我看看add函數,它會每次添加具有相同ID的元素。 –