Fancybox v2.1.3 ajax load form

风格不统一 提交于 2019-12-13 04:43:02

问题


Hi again to all fancybox lovers. I got stuck with ajax load an external html form into current viewed html file. I use a hidden trigger with class="fancybox.ajax" in a tag that is brought into html that way:

$('body').prepend('<a class="fancybox fancybox.ajax" href="form.html" style="display: none;"></a>');

so that form can be brought next with following into html:

$(".fancybox.ajax").trigger('click'); 

But this fails. Maybe i need "on" or "live". I do not know if there is a better way to achieve this. Then i want to make some js checks over form submission but how this will run? Maybe some good use of "on"

 $('#submit').on(click, function({ .... }));  

Any help will be much appreciated.


回答1:


Rather try

$(".fancybox").trigger('click'); 

... the class fancybox is used to bind such selector to fancybox while the fancybox.ajax class is used to define the type of content (you don't need to use live since fancybox v2.x already uses that method)

On the other hand, if you want to perform some actions on form submit, try binding the .on() method to the form selector (not the submit button) like

$('#formSelector').on("submit", function({ //do somthing })); 



回答2:


Ok the answer to submit the form that is brought with ajax is only

$("#submit").live('click', function() { ... });

till now, i could not make on() to work by no means.



来源:https://stackoverflow.com/questions/13553308/fancybox-v2-1-3-ajax-load-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!