简体   繁体   English

更改时为document.body /更改时未选择,没有错误-jQuery 1.3.1

[英]document.body on change/select on change not firing, no errors — jquery 1.3.1

I am limited to using jquery 1.3.1 for this project, so can't update jquery. 我仅限于将此项目使用jquery 1.3.1,因此无法更新jquery。 I am trying to get one select field to disable another select field on change. 我正在尝试获取一个选择字段,以在更改时禁用另一个选择字段。

I have tried this: 我已经试过了:

$(document.body).on('change','#idoffirstselect',function(){
    var selected = $("#idoffirstselect").val();
    if (selected == "foo") {
      $("#selecttwo").attr('disabled','disabled');
    } else {
      $("#selecttwo").removeAttr('disabled');
    }  
 });

And this: 和这个:

$( "#idoffirstselect" ).change(function(){
  var selected = $("#idoffirstselect").val();
  if (selected == "foo") {
    $("#selecttwo").attr('disabled','disabled');
  } else {
    $("#selecttwo").removeAttr('disabled');
  }  
});

Any suggestions? 有什么建议么? Is there anything else I could try? 还有什么我可以尝试的吗? Firebug is not showing any errors. Firebug没有显示任何错误。

Since on is not available in version before 1.7 , try to use live() here: 由于1.7之前的版本中没有on ,请尝试在此处使用live()

$(function() {
    $('select').live('change', function(){
        var selected = $("#idoffirstselect").val();
        if (selected == "foo") {
            $("#selecttwo").attr('disabled','disabled');
        } else {
            $("#selecttwo").removeAttr('disabled');
        }  
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM