下面的代码是一个简单的通讯注册小部件。我该如何重构这个jQuery代码?
我敢肯定有一种方法,使之更加简明扼要,任何想法?
var email_form = $('.widget_subscribe form');
var email_submit = $('.widget_subscribe .submit');
var email_link = $('.widget_subscribe .email');
// Hide the email entry form when the page loads
email_form.hide();
// Show the form when the email link is clicked
$(email_link).click(function() {
$(this).toggle();
$(email_form).toggle();
return false;
});
// Hide the form when the form submit is clicked
$(email_submit).click(function() {
$(email_link).toggle();
$(email_form).toggle();
});
// Clear/reset the email input on focus
$('input[name="email"]').focus(function() {
$(this).val("");
}).blur(function() {
if ($(this).val() == "") {
$(this).val($(this)[0].defaultValue);
}
});
看起来不错。你只想念);在最后的模糊功能之后。 – 2009-05-05 13:48:34