When you do javascript:submitComment()
that's calling a the global function submitComment
. Since the submitComment
is defined in the jQuery(function($) { ... })
function, it is not a global. Therefore, window.submitComment
is undefined
(hence undefined is not a function
).
The globals are stored in the window
object.
Therefore, you can expose that submitComment
as a global:
window.submitComment = function () {...}
Note that you should avoid using globals as much as possible. In this case you can do that by adding:
$("#submit").click(submitComment);
// In this case, you shouldn't declare submitComment as a global anymore
And since you are in a form, you want to stop the default browser behavior when clicking the a
element, by using return false
at the end of the function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…