jQuery笔记

// ID元素下的所有input,并设置为不可用
$( " input " , $( " #id " )).attr( " disabled " true );

 

// 设置name为test的checkbox是否为选中状态。返回值为true|false
$( " input[name='test'] " ).attr( " checked " );

 

// 下拉列表值改变时触发
$(document).ready(function () {
    $(
" select " ).change(function () {
         alert($(
this ).val());
    })
})

 

// 查找含有date-myself属性的input对象
$( " :input[date-myself] " )

 

// 全选,取消全选
$( " #全选复选框ID " ).click( function  () {
   $(
" input[name='单个复选框name值'] " ).attr( " checked " , $( this ).attr( " checked " ));
})

// 点击所有,全选选中。全选状态下,取消一个选择,全选取消
var  checkBoxCount  =  $( " input[name='CalculateCheck'] " ).length;
$(
" input[name='CalculateCheck'] " ).click( function  () {
        
var  checkedCount  =  $( " input[name='CalculateCheck']:checked " ).length;
        $(
" #CalculateChkAll " ).attr( " checked " , checkBoxCount  ==  checkedCount);
})

 

//juqery UI中,弹出层并加载指定页面。
function  ShowDialog(url) {
   $(
" #DivID " ).dialog({
      autoOpen: 
true ,
      width: 
650 ,
      height: 
500
      resizable: 
true ,
      title: 
" 测试 " ,
      modal: 
true ,
      open: 
function  (event, ui) {
              $(
this ).load(url  +   " ? "   +  event.timeStamp,  null function  () {
              $(
" :input:first " ).focus();
              });
            },
      close: 
function  (event, ui) {
                $(
" #DivID " ).children().remove();
                }
   });
}

 

// 下拉列表选中的text值
$( " #下拉列表ID " ).find( " option:selected " ).text();
// 获取下拉列表选中的索引
$( " #ddlregtype  " ). get ( 0 ).selectedindex

// 获取下拉列表选中的value  
$( " #下拉列表ID " ).val();

// 获取下拉列表选中的索引:
$( " #下拉列表ID " ). get ( 0 ).selectedindex;

// 设置下拉列表选中的索引(index为索引值):
$( " #下拉列表ID " ). get ( 0 ).selectedindex = index;

// 设置下拉列表选中的value:
$( " #下拉列表ID " ).attr( " value " , " normal");
$( " #下拉列表ID " ).val( " normal " );
$(
" #下拉列表ID " ). get ( 0 ).value  =  value;
 
// 设置下拉列表选中的text:
var count = $( " #下拉列表IDoption " ).length;
for (var i = 0 ;i < count;i ++ )  
{        
    
if ($( " #下拉列表ID " ). get ( 0 ).options[i].text  ==  text)  
        {  
            $(
" #下拉列表ID " ). get ( 0 ).options[i].selected  =   true ;  
            
break ;  
        }  
}

$(
" #下拉列表ID option[text='jquery'] " ).attr( " selected " true );
 
// 设置下拉列表option项:

// 添加一项option
$( " #下拉列表ID " ).append( " <option value='value'>text</option> " );
 
// 在前面插入一项option 
$( " #下拉列表ID " ).prepend( " <option value='0'>请选择</option> " );

// 删除索引值最大的option 
$( " #下拉列表ID option:last " ).remove(); 
// 删除索引值为0的option
$( " #下拉列表ID option[index='0'] " ).remove();
// 删除值为3的option
$( " #下拉列表ID option[value='3'] " ).remove(); 

// 删除text值为4的option
$( " #下拉列表ID option[text='4'] " ).remove(); 
 
// 清空 select:
$( " #下拉列表ID " ).empty();

    

 

// jquery parseJSON
var  obj =   $.parseJSON( ('{"name":"John"}');
alert( obj.name === "John" );

 

//英文字符转大写
$( ' input[type="text"] ' ).each(cfunction (n, v) {
        $(v).keyup(function (e) {

             $(v).val($(v).val().toLocaleUpperCase());
        });
});

转载于:https://www.cnblogs.com/dfzone/archive/2011/06/18/2077362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值