私はJSの初心者として、選択メニューの「無効」機能を表示および非表示にする非常に単純なスクリプトを作成しました。
selectmenuのjQueryUIをロードするまで、すべてが正常に機能します。その後、それはもう動作しません。
私はそれを解決するために一日中試みましたが、できません。おそらく誰もが私を助けることができます。
// Metadata
$('#year').change(function(){
var sel = $(this);
var val = sel.val();
if(val == "2008")
{
$('#c2').find("option:eq(1)").removeAttr("disabled");
}
else
{
$('#c2').find("option:eq(1)").attr("disabled", "disabled");
}
});
何が起こるかというと、誰かが#yearから「2008」を選択すると、#c2のオプション1が有効になり、その逆も可能になります。
ここでは可能と思われますが、スクリプトを自分の試行錯誤に限定することはできません。
更新されたコード
<script>
// Metadata
$("#year").selectmenu({
// listen to the select event of the custom menu, not the original dropdown
select: function(){
var val = $(this).val();
if(val == "2008"){
$("#c2").find("option:eq(2)").removeAttr("disabled");
}
else{
$("#c2").find("option:eq(2)").attr("disabled", "disabled");
}
// must call this to reflect the change
$("#c2").selectmenu("refresh");
}
});
</script>