how can i trigger this function开发者_高级运维 without using the form submit?
$('#myForm').submit(function()
{ ....
You could try -
$('#myForm').trigger('submit');
Working demo - http://jsfiddle.net/ipr101/KvwMb/1/
You can directly use something like this
$('#button1').click(function(){
$('#search').submit();
});
Or you can use it from any javascript code. Which will trigger your $('#myForm').submit(function(){.....
function code.
return false;
adding this to function will stop the form submitting.
Or if you want to call function on a different event put the function in an appropriate event handler (a non-submit button's click?)
<input type="button" id="btn" value="click">
jquery
$(function(){
$('#myForm').submit(function()
{ ....});
$("#btn").click(function(){
$('#myForm').trigger('submit');
});
});
You will have to dig it from DOM data. But, let me tell you, its not recommended. Try this,
var form = $('#myForm');
var data = form.data();
var events = data.events;
If the handler function is attached to form 'submit', it will be present as,
var submit_list = events.submit;
Now, if all goes well, at best you can get submit_list
as list of all the handler objects attached to submit event of form.
Shortcut:
Assuming you have one and only one handler attached to submit event for #myForm
,
$('#myForm').data().events.submit[0].handler
is your function.
Play with data()
, but remember its not recommended. Happy Coding.
精彩评论