一旦使用了jQuery日期选择器,无法使“保存更改”按钮不灰

Cannot get the "save changes" button to be ungreyed once the jQuery datepicker is used

本文关键字:保存更改 按钮 jQuery 选择器 日期      更新时间:2023-09-26
出于

某种原因,我的代码似乎忽略了一个事实,即当使用 jQuery 日期选择器选择日期时,它应该重新启用我的"保存更改"按钮。如果我更改任何其他输入框中的值,它似乎工作正常。我似乎无法完全弄清楚这一点并绕开这个问题。

<!doctype html>
<html>
<head>
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();

$('.check input').keyup(function() { $('#save').attr('disabled', false); });
$( "#save" ).click(function() { $('#save').attr('disabled', true); });

});
</script>
</head>
<body>
<table class="check">
    <tr>
        <td><input type="text" id="txt1" value="text1"></td>
        <td><input type="text" id="txt2" value="text2"></td>
        <td><input type="text" id="txt3" value="text3"></td>
    </tr>
    <tr>
        <td><input type="text" id="txt4" value="text4"></td>
        <td><input type="text" id="txt5" value="text5"></td>
        <td><input type="text" id="txt6" value="text6"></td>
    </tr>
    <tr>
        <td><input type="text" id="txt7" value="text7"></td>
        <td><input type="text" id="txt8" value="text8"></td>
        <td><input type="text" id="datepicker" />Date Picker</td>
    </tr>
    </table>
<input id="save" type="button" value="save changes" disabled> 
</body>
</html>

使用 .onSelect 和 .prop((。

.prop(( 方法提供了一种显式检索属性值的方法,而 .attr(( 检索属性

$("#datepicker").datepicker({
    onSelect: function () {
        $('#save').prop('disabled', false);
    }
});