![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 230 Pomógł: 3 Dołączył: 8.01.2008 Ostrzeżenie: (10%) ![]() ![]() |
Piszę shoutboxa w oparciu o jQuery. Jest to formularz, do zdarzenia submit formularza wrzucam wysłanie wiadomości. W FF po wciśnięciu enter - wiadomość się wysyła, a w IE - strona przechodzi do action formularza ;/ Blokuje to poprzez return false;, ale widocznie IE to ignoruje. Czytałem też coś o preventDefault() w jQuery (ma zapobiegać domyślnej akcji danego zdarzenia), ale jakoś mi nie działa. Tak wygląda aktualny skrypt tego shoutboxa:
Kod function reShout(){ $.getJSON( "/", {page:"getShout",nr:$("#last").val()}, function(mesgs){ $.each(mesgs.mesg,function(n,item){ var newMesg=$("<div>"); newMesg.addClass("item"); newMesg.addClass(item.class); newMesg.html("<strong>"+item.autor+"</strong> <small>"+item.date+"</small><br/>"+item.text); $("#shoutbox").append(newMesg); }); $("#last").val(mesgs.lastNr); $("#shoutbox").attr("scrollTop",$("#shoutbox").attr("scrollHeight")-$("#shoutbox").attr("offsetHeight")); } ); setTimeout("reShout();",3000); } $(document).ready(function(){ $("form[@name='shoutForm']").submit(function(event){ $.post("/sendMesg", {mesg:this.mesg.value}, function(){ reShout(); }); this.mesg.value=""; return false; event.preventDefault(); }); reShout(); }); A tak html: Kod <form name="shoutForm" method="post" action="/sendShout"> <div id="box_komunikator"> <div class="box_tytul">» Komunikator</div> <div style="height:300px; overflow-y:scroll;" id="shoutbox"></div> <input type="text" name="mesg" style="width:220px; padding:5px; margin-left:20px; margin-top:20px; border: solid 1px #AB1B15; background:#fff; font: 800 11px tahoma; color:#444; display:block;"/> <input type="submit" value="Wyślij" style="margin:5px 20px 5px 0; float:right"/> <input type="hidden" id="last" name="last" defaultValue="0" value="0" /> </div> </form> W tym inpucie #last przechowuje ID ostatnio pobranej wiadomości. Jak można w IE zapobiec wysyłaniu się formularza? A może jest jakiś lepszy sposób na shoutbox, np. bez formularza? Ale wtedy trzebaby jakoś ustawić enter=wysłanie wiadomości... Proszę o pomoc w rozwiązaniu tego ![]() Znalazłem rozszerzenie do jQuery - form, ale i z tym IE przekierowuje do action formularza, zamiast tylko wykonać request ajaxem ;/ Ten post edytował Apocalyptiq 23.11.2008, 17:51:15 -------------------- http://estender.net - profesjonalne strony i aplikacje internetowe (Ruby on Rails, Kohana PHP)
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 20.08.2025 - 05:10 |