它与基于ajax / jquery 1.3.2的注册表单有关。我想通过逐行理解代码/语法来学习如何制作它并使用jquery。
有人可以解释这段代码试图完成的内容以及它是如何逐行完成的吗?
<script type="text/javascript">
$(document).ready(function(){
// Email Signup
$("form#sub_name").submit(function() {
var dataStr = $("#UserEmail").val();
$.ajax({
type: "POST",
url: "signup.php",
data : {UserEmail: dataStr},
success: function(del){
$("#signup-success").html(del);
$("#signup-success").fadeIn();
$('#signup-success').fadeOut(10000);
}
});
return false;
});
});
谢谢!
答案 0 :(得分:3)
代码在评论中解释。
<script type="text/javascript">
$(document).ready(function(){ // run this code on page load
// Email Signup
$("form#sub_name").submit(function() { // activate on form submit for sign in
// the id of the form is sub_name
var dataStr = $("#UserEmail").val(); // get the email address from an
// input field with ID UserEmail
$.ajax({ // use and ajax call to signup.php
// using POST method
type: "POST",
url: "signup.php",
data : {UserEmail: dataStr}, // The parameter UserEmail is passed.
success: function(del){ // this part displays the success
$("#signup-success").html(del); // probably a div with id signup-success
$("#signup-success").fadeIn(); // is faded in and
$('#signup-success').fadeOut(10000); // removed after 10 seconds
}
});
return false;
});
});