[英]document.body on change/select on change not firing, no errors — jquery 1.3.1
我僅限於將此項目使用jquery 1.3.1,因此無法更新jquery。 我正在嘗試獲取一個選擇字段,以在更改時禁用另一個選擇字段。
我已經試過了:
$(document.body).on('change','#idoffirstselect',function(){
var selected = $("#idoffirstselect").val();
if (selected == "foo") {
$("#selecttwo").attr('disabled','disabled');
} else {
$("#selecttwo").removeAttr('disabled');
}
});
和這個:
$( "#idoffirstselect" ).change(function(){
var selected = $("#idoffirstselect").val();
if (selected == "foo") {
$("#selecttwo").attr('disabled','disabled');
} else {
$("#selecttwo").removeAttr('disabled');
}
});
有什么建議么? 還有什么我可以嘗試的嗎? Firebug沒有顯示任何錯誤。
由於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.