私のVB.NETプロジェクトには、いくつかのテキスト入力フィールドと保存/送信ボタンを備えたUIがあります。ページの読み込み時に保存ボタンを無効な状態にして、入力の1つに変更が加えられるまでその状態を維持したいと思います。また、ユーザーが入力した値がページの読み込み時と同じである場合は、保存ボタンを再び無効にする必要があります。したがって、基本的に、保存ボタンは実際に変更があった場合にのみ有効にする必要があります。
jqueryを使用してこれを行うにはどうすればよいですか?
私のVB.NETプロジェクトには、いくつかのテキスト入力フィールドと保存/送信ボタンを備えたUIがあります。ページの読み込み時に保存ボタンを無効な状態にして、入力の1つに変更が加えられるまでその状態を維持したいと思います。また、ユーザーが入力した値がページの読み込み時と同じである場合は、保存ボタンを再び無効にする必要があります。したがって、基本的に、保存ボタンは実際に変更があった場合にのみ有効にする必要があります。
jqueryを使用してこれを行うにはどうすればよいですか?
$(':input').change(
function(){
$("#submitButtonId").prop("disabled",false);
}
);
あなたはそれが動的だと言ったので、使用しますon
。
$(document).on("change", ":input",
function(){
$("#submitButtonId").prop("disabled",false);
}
);
change
イベントでそれを処理できます
$('input[type="text"]').on('change', function() {
// Change event fired..
$('input[type="submit"]').prop('disabled', false);
});
//This will bind all existing and dynamically added selects onChange to the handler
$(document).on('change', function(e) {
onChangeHandler();
}
// handle the event
function onChangeHandler() {
if (checkValues()) {
$('#yourButtonId').prop("disabled", false);
}
else {
$('#yourButtonId').prop("disabled", true);
}
}
// check all values against originals - data-* attributes are a good way to store data on
// an element. So have you can have:
<select id="id1" data-originalvalue="myValue"></select>
// compare the current value to the original value - if any one of them differ, return
// true
function checkValues() {
$.each($('select[data-originalvalue]'), function() {
if ($(this).val() !== $(this).attr(data-originalvalue){
return true;
}
return false;
});
}