簡體   English   中英

jQuery-禁用所有選擇框?

[英]jquery - disable all select boxes?

我有很多選擇框(約100多個),每個都有自己的唯一選擇ID。 我現在想禁用所有選擇框,以防用戶沒有足夠的訪問級別,但似乎找不到一種全局尋址所有選擇框的方法。

下面我嘗試通過JS做到這一點:

$(document).ready(function() {
    $('select').on('load', function () {
        this.attr('disabled', true);
    });
});

做就是了:

$(document).ready(function() {
    $('select').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").prop("disabled", "true");
});

//you should use prop intead

這樣做:

$(document).ready(function() {
    $('select').prop('disabled', true);;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM