$(document).ready(function(){ /* $(window).on('beforeunload', function () { return '投稿が完了していません。このまま移動しますか?'; }); $(".flowMove").click(function () { $(window).off('beforeunload'); }); */ $("input[type=text],textarea").each(function(index, elm) { var inputName = $(elm).attr("name"); if($(elm).siblings('#'+inputName+'_request_msg').size()>0){ $(elm).blur(function(){ if ($(this).val().length < 1) { $(this).css('background-color', '#ffebf5'); console.log($('#'+inputName+'_request_msg')); $('#'+inputName+'_request_msg').removeClass('hide'); } else { $(this).css('background-color', 'white'); $('#'+inputName+'_request_msg').addClass('hide'); } }).focus(function(){ $(this).css('background-color', 'white'); $('#'+inputName+'_request_msg').addClass('hide'); }); } }); $('input[name=user_mail]').blur(function(){ if ($(this).val().length < 1) { $(this).css('background-color', '#ffebf5'); $('#user_mail_request_msg').removeClass('hide'); } else { $('#user_mail_request_msg').addClass('hide'); if (!$(this).val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) { $(this).css('background-color', '#ffebf5'); $('#user_mail_format_msg').removeClass('hide'); } else { $(this).css('background-color', 'white'); $('#user_mail_format_msg').addClass('hide'); } } }).focus(function(){ $(this).css('background-color', 'white'); $('#user_mail_request_msg').addClass('hide'); $('#user_mail_format_msg').addClass('hide'); }); $('textarea[name=user_comment]').blur(function(){ if ($(this).val().length < 1) { $(this).css('background-color', '#ffebf5'); $('#user_comment_request_msg').removeClass('hide'); } else { $(this).css('background-color', 'white'); $('#user_comment_request_msg').addClass('hide'); } }).focus(function(){ $(this).css('background-color', 'white'); $('#user_comment_request_msg').addClass('hide'); }); });