Skip to content

Instantly share code, notes, and snippets.

@tag1216
Last active October 7, 2016 07:36
Show Gist options
  • Save tag1216/409f365829bb7da39b3d925c0f9399a0 to your computer and use it in GitHub Desktop.
Save tag1216/409f365829bb7da39b3d925c0f9399a0 to your computer and use it in GitHub Desktop.
フォームに変更がないときはsubmit不可
<script>
$(function() {
$("form :submit").prop("disabled", true);
var getValues = function() {
return $("form :input").map(function() {
return $(this).val();
}).get();
}
var oldValues = getValues();
$("form :input").on("change keyup dp.change", function() {
var newValues = getValues(),
changed = newValues.some(function(e, i) { return e != oldValues[i] });
$("form :submit").prop("disabled", !changed);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment