2017-06-19 3 views
0

Ich kann nicht jQuery .submit() auf mein Formular feuern. Die unten stehende Warnung wird erfolgreich angezeigt, wenn ich sie nach $ (document) .ready() verschiebe, aber der Versuch, sie beim Senden zu aktivieren, funktioniert einfach nicht.nicht jQuery .submit() zu feuern

Verwenden Sie das folgende Skript in meinem Körper

<script> 
    $(document).ready(function($) { 
    $('mainForm').submit(function() { 
     alert("hello"); 
    }); 
    }); 
</script> 

Und Formelement unter

<form id="mainForm" class="form-horizontal" method="POST"> 
<legend>Retrieve Your Documents</legend> 
<fieldset> 

<!-- Text input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="id">Request ID</label> 
    <div class="col-md-4"> 
    <input id="requestid" name="requestid" type="text" placeholder="DOC123456-123456789" class="form-control input-md" required=""> 
    </div> 
</div> 

<!-- Password input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="lastfour">Last Four of SSN</label> 
    <div class="col-md-4"> 
    <input id="lastfour" name="lastfour" type="password" placeholder="1234" class="form-control input-md" required=""> 
    </div> 
</div> 

<!-- Button --> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="button"></label> 
    <div class="col-md-4"> 
    <input type="submit" id="button" name="button" class="btn btn-primary" value="Retrieve Documents"> 
    </div> 
</div> 

</fieldset> 
</form> 
+3

'$ ('# mainForm')': Sie vermissen die '#' – haim770

+0

Dies Hat den Trick gemacht, aber ich hatte das schon vorher probiert und es hat nicht funktioniert. Ich habe jedoch explizit HTML4 als DOCTYPE verwendet. Als ich zu HTML5 wechselte, funktionierte es wie erwartet. – vermi

Antwort

1

Wie haim770 sagte mainForm die ID des Formulars ist daher müssen Sie es mit einem # Präfix wie dies:

$('#mainForm').submit(function() { 
    alert("hello"); 
});