0

I am trying to test multiple select boxes each when they change their option. But I can't even get it to pop up an alert message when one of them changes. Here's the code:

<div id="event_date_box">
    <script>
        j('#event_date_box select').change( function() {
            alert('changed');
        });
    </script>

    <select id="event_date_month">
        <option>Jan</option>
        <option>Feb</option>
        ...
    </select>
    <select id="event_date_day">
        <option>1</option>
        <option>2</option>
        ...
    </select>
    <select id="event_date_year">
        <option>2012</option>
        <option>2013</option>
        ...
    </select>
</div>

Also I tried changing the JavaScript to:

j('#event_date_box select').each( function() {
    j(this).change( function() {    
        alert('changed');
    });
});

But the alert window doesn't pop up at all.

4

2 回答 2

2

等待 DOM 准备好:

j(function(){    
    j('#event_date_box select').change( function() {
                alert('changed');
            });
});
于 2013-06-27T19:49:28.520 回答
1

您需要正确使用 jQuery。

    <script>
         $(document).ready(function(){
            $('#event_date_box select').change(function(){
                alert('changed');
            });
         });
    </script>
于 2013-06-27T19:50:32.780 回答