Показать страницуИстория страницыСсылки сюдаCopy this pageExport to MarkdownODT преобразованиеНаверх Вы загрузили старую версию документа! Сохранив её, вы создадите новую текущую версию с этим содержимым. Медиафайлы====== JQuery Вопросы / Ответы ====== ===== Q-A ===== ==== Как сделать метод в JQuery ==== <code javascript> (function($) { jQuery.fn.doSomething = function() { return this.each(function() { var $this = $(this); $this.click(function(event) { event.preventDefault(); // Your function goes here }); }); }; })(jQuery); // А так можно бкдет потом вызвать метод $(document).ready(function() { $('#div1').doSomething(); $('#div2').doSomething(); }); </code> * A: <code javascript> $(function() { // Way 1 function doosomething() { //Doo something } // Way 2, equivalent to Way 1 var doosomething = function() { // Doo something } $("div.class").click(doosomething); $("div.secondclass").click(doosomething); }); </code> ==== Выполнение нескольких запросов AJAX через jQuery .post ==== http://js-prog.blogspot.com/2012/06/ajax-jquery-post.html ==== Отправка данных форм ссылкой с помощью js/jquery ==== <code html> <script> $(document).ready(function(){ $("#submit").click(function(evt){ evt.preventDefault(); $("#form").submit(); }) }) </script> <form id="form"> <a id="submit" href="#">Submit</a> </form> </code> ==== Отправить POST с ипользованием Ajax ==== A: <code html> <form name="myform" id="myform" action="" method="POST"> <!-- The Name form field --> <label for="name" id="name_label">zoom</label> <input type="text" name="zoom" id="zoom" size="30" value=""/> <br> </select> <script type="text/javascript"> $(document).ready(function(){ $("#myform").submit( function () { $.post( 'post.php', $(this).serialize(), function(data){ $("#results").html(data) } ); return false; }); }); </script> </code> ==== Отправить POST с ипользованием Ajax ==== <code html> $('select').change(function(){ var v = $(this).val(); $.ajax({ type: "POST", url: "obr.php", data: "val="+v, success: function(msg){ alert( "Data Saved: " + msg ); } }); }); </code> ==== Модальное окно ==== <code javascript> $("body").on("click", ".js-user-confirm-modal", function() { var id = $(this).data("id"); var deal = $(this).data("deal"); $.ajax({ method: "GET", url: "<?= $get_user_form?>?userId="+id+"&dealId="+deal, dataType: "html", }).done(function( data ) { $(".js-user-modal-content").html(data); $("#userConfirm").modal("show"); }); }); </code> <code html> <h4>Покупатель <a href="javascript:void(0)" class="js-user-confirm-modal"> <span class="glyphicon glyphicon-pencil"></span> </a> </h4> </code> <code html> <div class="modal fade" id="userConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content js-user-modal-content"> ... </div> </div> </div> </code> СохранитьПросмотрРазличияОтменить Сводка изменений Примечание: редактируя эту страницу, вы соглашаетесь на использование своего вклада на условиях следующей лицензии: CC0 1.0 Universal