JQuery禁用radio、select、checkbox的实现代码
本文导语: 代码如下: 代码示例: /** * 禁用radio、select、checkbox * edit www. */ $(document).ready(function(){ var input = $("#appDIV").find("input:radio"); input.attr("disabled","disabled"); input.each(function(){ if($(this).val()==2){ ...
代码如下:
/**
* 禁用radio、select、checkbox
* edit www.
*/
$(document).ready(function(){
var input = $("#appDIV").find("input:radio");
input.attr("disabled","disabled");
input.each(function(){
if($(this).val()==2){
$(this).attr("checked",true);
}
});
var checkbox = $("#ce").find("input:checkbox");
checkbox.attr("disabled","disabled");
checkbox.each(function(){
if($(this).val()=="Monthly"){
$(this).attr("checked",true);
}
});
$("#selectItem option:disabled").css('color', '#CCC');
$('#selectItem').change(function(){
if(this[this.selectedIndex].disabled){
this.selectedIndex = this.s||0;
}else{
this.s = this.selectedIndex||0;
}
});
$("#selectItem").attr("disabled","disabled");
});
1
2
3
Flowers
Gardens
Trees
Dairy
Weekly
Monthly
运行结果如下面的二张图所示:
(方法一)
(方法二)