jQuery笔记

it2022-05-05  118

// 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

相关资源:jquery笔记大全

最新回复(0)