我想呼吁一下形式的一个按钮jQuery的功能,在这里调用一个jQuery查询是我使用上点击一个按钮
按钮代码代码:
<input type="submit" src="images/submitbutton.png" alt="Submit button" name="submit_button" class="submit_button" id="submit_button">
形式出发代码
<form method="post" action="" id="contactForm">
jQuery代码
<script type="text/javascript">
$(document).ready(function() {
//if submit button is clicked
$('input[name=submit_button]').submit(function() {
alert("testing")
.....
我试过所有的提交按钮来调用jquery函数但无济于事(我尝试使用submit()或click())。
什么可能我是做错了(此表格位于HTML页)
编辑:刚插入的jQuery函数我试图运行的代码,我实际上是想利用调用PHP脚本AJAX,然后隐藏表单如果表单提交成功
$(document).ready(function() {
//if submit button is clicked
$('#submit_button').submit(function() {
alert("testing") /*get the email value*/
var name = $('input[name=name]');
var email = $('input[name=email]');
var subject= $('input[name=subject]');
var message = $('textarea[name=message]');
data = 'name=' + name.val() + '&email=' + email.val() + '&subject=' +
subject.val() + '&message=' + encodeURIComponent(message.val());
//disabled all the text fields
$('.text').attr('disabled','true');
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "mai.php",
//GET method is used
type: "POST",
//pass the data
data: data,
//success
success: function() {
$('.contact_form').fadeOut('slow');
//show the success message
$('.simple-sucess').fadeIn('slow');
//if process.php returned 0/false (send mail failed)
}
});
//cancel the submit button default behaviours
return false;
});
});
</script>
相关:http://stackoverflow.com/questions/5411198/on-click-with-button-in-jquery – 2012-01-27 01:53:58