问题
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