一些模糊的基础知识

  1. forEach和each这2中循环function里面的index和obj?
//  forEach适用场合
var arr = ["a=1", "value=2", "key=3"];
arr.forEach(function (obj,index) {
  console.log(obj);
  console.log(index);
})

//  each适用场合
  • 11
  • 22
  • 33
$('.box li').each(function (index,obj) { console.log(index); console.log(obj); })
  1. return的作用

1.阻止程序执行
2.函数封装的时候,return出去结果

  1. onclick = "javascript:method()" javascript:起什么作用?

onclick方法负责执行js函数

  1. onclick = "return method()" return起到什么作用?

把method函数的返回值,反馈回来

  1. onclick 和 click 的区别?

onclick是一个事件
click 是一个方法

//  onclick
  • 11
  • function ceshi() { alert(1); } // click
  • 11
  • $('.ceshi').click(funciton(){ alert(1); })
    1. $(function() {}) 是什么写法?(function() {})()是什么?

    $(function(){}) 是 $(document).ready(function() 的简写

    (function() {})() 是 javascript的立即执行函数

    1. $.fn.方法名=function(){} 和 $.fn.extend({}) 和 $.extend() 区别?
      参考:https://www.cnblogs.com/qicao/p/8568158.html

    jQuery.fn === jQuery.prototype
    $.fn.method()=function(){}的调用把方法扩展到了对象的prototype上。

    $.fn.blueBorder = function(){
     this.each(function(){
      $(this).css("border","solid blue 2px");
     });
     return this;
    };
    $.fn.blueText = function(){
     this.each(function(){
      $(this).css("color","blue");
     });
     return this;
    };
    

    $('.blue').blueBorder().blueText();

    jq为开发插件提拱了两个方法:
    jquery.fn.extend()
    jquery.extend()

    $.fn.extend({
        a: function() { },
        b: function() { }
    });
    等效于
    $.fn.a = function() { };
    $.fn.b = function() { };
    
    1. 类和对象

    类:模子 Array (原型是在类的上面加的),作用就是创建东西
    对象:产品 arr (仅仅可以使用) 我们真正使用的是对象。
    var arr=new Array(1,2,3);

    1. 字符串和数组的常用方法

      字符串常用方法:

      • str.charAt(下标) 返回字符串中 指定位置的字符
      • indexOf 查找字符在字符串中的位置,如果没找到 返回-1
      • lastIndexOf 从后往前查找字符在字符串中的位置,如果没找到 返回-1 ,位置从前往后算
      • substring(开始位置,结束位置)
        截取字符串,如果不写结束位置那么截取到最后
      • split(分割符) 字符串分割 分割出来的东西是一个数组
      • toUpperCase() 大写
      • toLowerCase() 小写

    数组常用方法:
    arr = [12,5];

    方法 例子 结果 说明 返回值
    arr.push() arr.push(8) [12,5,8] 向后插入 新数组的长度
    arr.pop() arr.pop() [12] 从后删除 删除的元素
    arr.unshift() arr.unshift(9) [9,12,5] 向前插入 新数组的长度
    arr.shift() arr.shift() [5] 从前删除 删除的元素
    • splice 总和了push、pop、unshift、shift的功能
      例: arr.splice(位置, 删除几个元素, 插入的元素);
    • join 数组变字符串
    1. 什么为真什么为假?
    类型 number string boolean obj undefined
    非零的数字 非空字符串 true 非空对象、数组(包括空数组) n/a
    0 ‘’ false null NaN、undefined

    你可能感兴趣的:(一些模糊的基础知识)