key up 和change 状态同时

浏览次数 :  9

<!DOCTYPE html>
    <title>Custom Filter Form</title>
    <script src=""></script>
    <form id="filterForm">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name">
        <label for="age">Age:</label>
        <input type="number" id="age" name="age">
        <label for="gender">Gender:</label>
        <select id="gender" name="gender">
            <option value="all">All</option>
            <option value="male">Male</option>
            <option value="female">Female</option>
        <label for="city">City:</label>
        <input type="text" id="city" name="city">

        // Function to handle form changes
        function handleFormChanges() {
            const name = $('#name').val();
            const age = $('#age').val();
            const gender = $('#gender').val();
            const city = $('#city').val();

            // Replace this with your custom filter function
            console.log('Filter Criteria:');
            console.log(`Name: ${name}`);
            console.log(`Age: ${age}`);
            console.log(`Gender: ${gender}`);
            console.log(`City: ${city}`);
            // Call your filtering function here with the filter criteria

        // Add event listeners to the form elements for both 'keyup' and 'change' events
        $('#filterForm input, #filterForm select').on('keyup change', handleFormChanges);

  • 标签1
  • 标签1
  • 标签1