Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Odświeżaj diva, jeżeli checkbox jest checked
Maxie
post
Post #1





Grupa: Zarejestrowani
Postów: 82
Pomógł: 1
Dołączył: 19.10.2011

Ostrzeżenie: (0%)
-----


Mam taki problem. Dostałem skrypt w JS, służący do odświeżania diva. Wygląda on następująco:
Kod
$("#rozmowa").show("fast").load("chat_core.php").show("fast");
        var refreshId = setInterval(function() {
            $("#rozmowa").show("fast").load('chat_core.php').show("fast");
        }, 100);
    $.ajaxSetup({ cache: false });

Jestem zielony w JavaScripcie a wolałbym gdyby odświeżało się jeżeli checkbox jest w pozycji checked. Wykombinowałem coś takiego:
Kod
if($('#refresh').attr('checked')) {
   var auto_refresh = setInterval(
    function ()
    {
    $('#rozmowa').load('chat_core.php').fadeIn("slow");
    }, 100); // refresh every 10000 milliseconds
} else {
    $('#rozmowa').load('chat_core.php').fadeIn("slow");
}]

Ale to niestety nie działa ;/ Więc co robię nie tak?

Ten post edytował Maxie 4.07.2012, 12:09:09
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mikolaj51
post
Post #2





Grupa: Zarejestrowani
Postów: 59
Pomógł: 13
Dołączył: 16.03.2012

Ostrzeżenie: (0%)
-----


Witaj,

spróbuj coś takiego, na szybko pisałem:

[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function(){
  2. var repeat;
  3. var auto_refresh = function(){
  4. $('#rozmowa').load('chat_core.php').fadeIn("slow");
  5. };
  6. auto_refresh();
  7.  
  8. $('#refresh').change(function(){
  9. if($('#refresh').attr('checked')) {
  10. repeat = setInterval(auto_refresh, 100);
  11. }
  12. else{
  13. repeat = clearInterval(repeat);
  14. }
  15. });
  16. });
[JAVASCRIPT] pobierz, plaintext
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 10:37