检测隐藏的表单字段何时动态更改

时间:2013-09-17 22:58:33

标签: javascript forms dynamic field dynamically-generated

我们如何检测隐藏的表单字段何时动态更改?如果已更改,则显示警告?

JQuery UI(DatePicker)用于更改隐藏的表单字段。

$("#datepicker").datepicker({altField: "#alternate", altFormat: "yymmdd"}).$('#alternate').trigger('change');


<input name="textbox" id="alternate" type="hidden" size="30" 
onchange="alert('changed')" />

2 个答案:

答案 0 :(得分:0)

$('#alternate').change(function(){
    window.alert('Change has happened.  Ya dig?');
});

答案 1 :(得分:0)

在StackOverflow.com上的两个类似问题的帮助下解决了这个问题

  1. jQuery UI datepicker - Trying to capture click event from date clicked
  2. jQuery - Detect value change on hidden input field

  3. <input name="textbox" id="alternate" type="hidden" size="30" 
    onchange="alert('changed')" />
    
    
    <script>
    $(function() {
        $("#myDatePicker").datepicker({
            // The hidden field to receive the date
            altField: "#alternate",
            // The format for the date
            altFormat: "yymmdd",
            onSelect: function (date) {
                // trigger the .change() event
                $('#alternate').trigger('change');
            }
        })
    });
    </script>