美文网首页
jQuery基本语法

jQuery基本语法

作者: Young_Blood | 来源:发表于2016-07-25 16:50 被阅读51次
// 1.  $() ---> jQuery对象        

// 2.  如何拿到对应的标签
            console.log($('p'));        

// 3.  查看拿到的标签中的属性值 
            console.log($('.word').attr('class'));        

// 4.  改变拿到的标签中的属性值  两种写法       
            $('img').attr('src', 'image/img_02.jpg');          
            $('img').attr({'src':'image/img_02.jpg'});   
     
// 5. 如何查看标签内容
            console.log($('p').text());           
            console.log($('p').html());        

// 6. 改变        
           $('p').text('我是MT');        

7. 事件        
// 7.1 显示        
           $('button').eq(0).on('click', function () {  
                 $('p').show();   
                 $('img').show();      
           });;        
// 7.2 隐藏       
           $('button').eq(1).on('click', function () {                  
                 $('p').hide();
                 $('img').hide();        
            });        
// 7.3 切换        
           $('button').eq(2).on('click', function () {            
                $('p').toggle(2000);           
                $('img').toggle(2000);        
            });       
 
// 8.遍历        
           var datas = [10,32,2323,4,4];   
           $.each(datas,function (index , value) {                    
                       console.log(index,value);        
           });     
   
// 9.取出对应下标        
          console.log($.inArray(32,datas));  

// 10写css        
          $('.word').css({            
                background:'red',            
                border:'3px solid green',        
          });

相关文章

  • jQuery

    jQuery框架 一、jQuery基础 添加jQuery到网页 jQuery基本语法 二、jQuery 选择器 示...

  • jQuery基本语法

  • jQuery

    1、引入jQuery 1.从jQuery.com下载jquery库2从CDN中载入jQuery 2、基本语法 基础...

  • 前端-4

    jQuery 基本语法: $(selector).action() 选择器 筛选器

  • jQuery - jQuery 简介

    本文目录如下: 什么是 jQuery; 文档就绪函数; 基本语法; 命名冲突问题。 什么是 jQuery? jQu...

  • jQuery

    基本语法 效果 jQ html jQ Ajax jQuery概述 jQuery由美国人John Resig于200...

  • 利用ajax实现与php数据交互,并局部刷新页面

    本文主要有以下几个要点: ajax的基本语法结构 jQuery基本语法 json数组基本结构 ajax回调函数中的...

  • jQuery

    jQuery 语法是通过选取HTML元素,并对选取的元素执行某种操作。 基本语法:$(selector).acti...

  • JQuery基本语法(样式篇)

    前言 其实并没有什么好说的,就是当作wiki方便查阅。用得多就会了。 $() 这是我们常用的方式。其意义为让页面加...

  • JQuery操作AjAx基本语法

    $.ajax({ type://提交类型 url://处理程序的URL data://提交的数据 dataType...

网友评论

      本文标题:jQuery基本语法

      本文链接:https://www.haomeiwen.com/subject/kpogjttx.html