我有很多(〜100 +)選擇框,每個都有自己獨特的選擇ID。我現在想禁用所有選擇框,以防用戶沒有足夠的訪問級別,但似乎無法找到全局地址解決所有選擇框的方法。jquery - 禁用所有選擇框?
下面我試圖通過JS來做到這一點:
$(document).ready(function() {
$('select').on('load', function() {
this.attr('disabled', true);
});
});
我有很多(〜100 +)選擇框,每個都有自己獨特的選擇ID。我現在想禁用所有選擇框,以防用戶沒有足夠的訪問級別,但似乎無法找到全局地址解決所有選擇框的方法。jquery - 禁用所有選擇框?
下面我試圖通過JS來做到這一點:
$(document).ready(function() {
$('select').on('load', function() {
this.attr('disabled', true);
});
});
你想這樣做的時候,身體已經加載:
$(document).ready(function() {
$('body').on('load', function()
{
$('select').prop('disabled', true);
});
});
$(document).ready(function() {
$("select").attr("disabled", "true")
});
除非你正在做一些時髦的AJAX加載, ready()事件應該沒事
你可以這樣試試
(function(){
$("select").attr("disabled", true);
})
只要做到:
$(document).ready(function() {
$('select').attr('disabled', true);
});
$(document).ready(function() {
$("select").prop("disabled", "true");
});
//you should use prop intead
這樣做:
$(document).ready(function() {
$('select').prop('disabled', true);;
});