My jquery submit handler is not called in Chrome
My jquery submit handler is not called in Chrome. Here is the code:
<input
accesskey="s"
class="button"
id="issue-link-submit"
name="Link"
title="Press Alt+s 开发者_运维百科to submit this form"
type="submit"
value="Link"
/>
<script type="text/javascript">
jQuery('#issue-link-submit').submit(function() {
alert('hi');
});
</script>
But it is working fine in IE and FF. Could you please help me on this? Thanks in advance!
-Chintu
Try:
<script type="text/javascript">
jQuery('#issue-link-submit').click(function(e) {
e.preventDefault;
alert('hi');
});
</script>
As scripts execute before the page is necessarily parsed and rendered, you must wrap all jQuery code which depends on the DOM in a document.ready callback.
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#issue-link-submit').submit(function() {
alert('hi');
return false; //prevent default?
});
}
</script>
Change your javascript code to this:
$("formId").submit(function() {
alert('hi');
return true;
});
Replace #issue-link-submit
with your form id. If there is no form id, then add an id to the form.
You can not add #issue-link-submit
selector to submit handler directly, because you are adding submit handler to the button. You need to add the submit handler to the form element.
精彩评论