jquery如何設定元素不可用?下面本篇文章給大家介紹一下。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

使用jQuery設定元素不可用
我們可以用jQuery改變HTML元素的非CSS的屬性。比如,你可以禁用按鈕。
當你把按鈕設定成禁用以後,按鈕會變灰并且不能點選。
jQuery有一個.prop()的方法,可以讓你來調整元素的屬性。
以下代碼顯示如何禁用所有按鈕:$("button").prop("disabled", true);
示例:讓target1按鈕禁用
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
});
jQuery Playground
#left-well
#target1
#target2
#target3
#right-well
#target4
#target5
#target6
效果圖:
更多web前端知識,請查閱 HTML中文網 !!