zepto.js

 

一,引入:

<script type="text/javascript" src="../../js/zepto.min.js"></script>

 二,理解:

zepto使用了几次后发现和jquery使用方法惊人的一致

1,加载

Zepto(function($){
  alert('Ready to Zepto!')
})

2,在每个匹配的元素后插入内容(愚人码头注:外部插入)。内容可以为html字符串,dom节点,或者节点组成的数组

HTML:
<form>
	<label>1111</label>
</form>
js:
$('form label').after('<p>this is after</p>');

3,append(content) ⇒ self

    在每个匹配的元素末尾插入内容(愚人码头注:内部插入)。内容可以为html字符串,dom节点,或者节点组成的数组

appendTo(target)   ⇒ self
将匹配的元素插入到目标元素的末尾(愚人码头注:内部插入)。这个有点像 append,但是插入的目标与其相反
html:

<ul>
	<li>111</li>
	<li>111</li>
	<li>111</li>
	<li>111</li>
</ul>

<ul>
	<li>111</li>
	<li>111</li>
	<li>111</li>
	<li>111</li>
</ul>

JS:

$('ul').append('<li>this is first</li>');

$('<li>this is second</li>').appendTo('ul');

4,attr

attr(name)   ⇒ string
attr(name, value)   ⇒ self
attr(name, function(index, oldValue){ ... })   ⇒ self
attr({ name: value, name2: value2, ... })   ⇒ self
读取或设置dom的属性。如果没有给定value参数,则读取对象集合中第一个元素的属性值。当给定了value参数。则设置对象集合中所有元素的该属性的值。当value参数为null,那么这个属性将被移除(类似removeAttr),多个属性可以通过对象键值对的方式进行设置。

var form = $('form')
var res = form.attr({
	action:'/create',
	method:'post'
});

5, each
$('form input').each(function(index){
  console.log('input %d is: %o', index, this)
})

具体实例:
http://www.runoob.com/manual/zeptojs.html#$()
原文地址:https://www.cnblogs.com/xiaoxiaomengxiangjia/p/5363869.html