jQuery笔记

/***************************选择器***********************/
根据元素id获取元素   $('#id')
获取值$('#id').val()

动态设置样式$("#id").attr('class','myclass');

获取单选按钮选中项的值
$("input:radio[name='injuryIdentify'][checked]").val()

/***************下拉列表操作********************/
根据下拉框的值,选中该项:
tmp="#sel_id option[value='"+值+"']";
$(tmp).attr("selected", "selected");

根据显示内容label选中
$("select[name=accidentWeatherCode]").find("option[text='其它']").attr("selected","selected");

选中下拉列表文本以‘估损注销审核’为结尾的,text$= 为通配符
$("select[name=orgId]").find("option[text$='估损注销审核']").attr("selected","selected");

//页面加载完成时执行
$(document).ready(function(){
         //给指定元素绑定点击事件 假设是给checkbox注册点击事件
$('#ck_injured').click(function(){
                   //$(this)即为当前操作的元素
    if ($(this).attr("checked")) {
                  alert("复选框已选中");
             } });
});

//禁用元素
$("input[name='injuryIdentify']").attr({"disabled":"disabled"});
//取消禁用
$("input[name='injuryIdentify']").removeAttr("disabled");

你可能感兴趣的:(jquery)