0

I posted this question yesterday: jQuery live check input changes - and I got my answer.

Now I am curious if I have drop-downs, checkboxes and radio buttons, how can I keep track of their change.

This is the current code for country :

<select id="country-list" name="countries">
  <option value="xx" selected="">Worldwide</option>
  <option value="in">India</option>
  <option value="il">Israel</option>
  <option value="ru">Russia</option>
  <option value="us">United States</option>
</select>

The rest is in this jsfiddle: http://jsfiddle.net/XeG5u/

Thanks!

EDIT: My goal, enter image description here

4

4 回答 4

1

似乎您为启用该按钮做了很多工作……我觉得您可以通过一个简单的.change()事件来处理其中的大部分内容。

$("#country-list").change(function() {
    if (this.value == "xx") {
        $("#submit-data").prop("disabled", true);
    } else {
        $("#submit-data").prop("disabled", false);
    }
});

演示:http: //jsfiddle.net/tymeJV/XeG5u/1/

每次下拉列表更改时,都会触发此事件。您可以存储选定的值(在此函数中可访问为this.value)并执行您需要的逻辑。

于 2013-05-16T13:12:59.807 回答
0

为此,您可以使用 jQuery 的.on('change', ...)事件处理程序:

$('body').on('change', 'select#country-list', function() {
    // When the selected option is changed, this function will be entered
});

JSFiddle 示例

于 2013-05-16T13:13:39.630 回答
0

我刚刚解决了我自己的问题。相当简单,在循环比较之前使用 find() 并获取默认值!谢谢各位!

这成功了:

var current = $("#country-list option[selected]").val();

然后执行 If() 语句……就是这么简单……

于 2013-05-16T14:04:30.280 回答
0

我会大大简化这一点:

var button = $('#submit-data');
$('#country-list').data('selected', $("#country-list option:selected").val()).change(function () {
    button.prop('disabled', ($(this).find('option:selected').val() === $(this).data('selected')));
});
于 2013-05-16T14:05:48.600 回答