jquery 常用方法&ajax

2016-10-17  本文已影响0人  饥人谷_徐小坤

1.Jquery 中,$(document).ready()是什么意思?和window.onload 的区别?还有其他什么写法或者替代方法?

2.$node.html()和$node.text()的区别?

3.$.extend 的作用和用法?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>jquery</title>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.js"></script>
</head>
<body>
<script>
  var opts1 = {
    "name": "hunger",
    "age": "20",
  }
  var opts2 = {
    "name": "valley",
    "sex": "nan"
  }
  $.extend(opts1, opts2);
  console.log(opts1);
  console.log(opts2);
  </script>
</body>
</html>
输出结果

4.JQuery 的链式调用是什么?

当jQuery的方法的返回值仍为当前对象时可以继续调用该对象的方法,这样就形成一种链式调用。

5.JQuery ajax 中缓存怎样控制?

通过设置cache来控制是否缓存页面,当值为true时,浏览器缓存页面;当值为false时,浏览器将不缓存此页面,默认值: true,dataType 为 script 和 jsonp 时默认为 false。

6.JQuery 中 data 函数的作用

在匹配元素上存储任意相关数据 或 返回匹配的元素集合中的第一个元素的给定名称的数据存储的值。

7.写出以下功能对应的 Jq 方法:

$node.addClass('active');// 添加 class
$node.removeClass('active');//删除 class
$node.show();//展示元素
$node.hide();//隐藏元素
$node.attr(id);$node.attr(src);$node.attr(title);//获取属性
$node.attr(id, 'header');$node.attr(src, 'http://baidu.com');$node.attr(title, 'pic');//修改属性
$node.data('data-src', 'htttp://baidu.com');
$ct.prepend($node);
$ct.append($node);
$node.remove();
$ct.empty();
$ct.html('<div class="btn"></div>');
$node.width();//不包括内边距、边框、外边距的宽度
$node.height();//不包括内边距、边框、外边距的高度
$node.innerWidth();//包括内边距的宽度
$node.innerHeight();//包括内边距的高度
$node.outerWidth();//包括内边距、边框的宽度
$node.outerHeight();//包括内边距、边框的高度
$node.outerWidth(true);//包括内边距、边框、外边距的宽度
$node.outerHeight(true);//包括内边距、边框、外边距的高度
$(document).scrollTop();
$node.offset();
$node.css({
  "color": "red",
  "font-size": "14px"
});
$node.each(function(){
    $(this).text().clone().appendTo($(this))
 })
$ct.children('.item');
$ct.find();
$node.parent('.ct').find('.panel');
$node.length;
$(this).index();
上一篇 下一篇

猜你喜欢

热点阅读