Skip to content

Instantly share code, notes, and snippets.

语法 描述
$(this) 当前 HTML 元素
$("p") 所有 <p> 元素
$("p.intro") 所有 class="intro" 的 <p> 元素
$(".intro") 所有 class="intro" 的元素
$("#intro") id="intro" 的元素
$("ul li:first") 每个 <ul> 的第一个 <li> 元素
$("[href$='.jpg']") 所有带有以 ".jpg" 结尾的属性值的 href 属性
$("div#intro .head") id="intro" 的 <div> 元素中的所有 class="head" 的元素
@ayuLiao
ayuLiao / replaceAll.js
Created January 19, 2019 11:05
想将变量的值与字符串中的某些值进行替换
//string:字符串表达式包含要替代的子字符串。
//reallyDo:被搜索的子字符串。
//replaceWith:用于替换的子字符串。
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if(!RegExp.prototype.isPrototypeOf(reallyDo)) {
return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
} else {
return this.replace(reallyDo, replaceWith);
//int型转换成string型
var x=100
a = x.toString()
var x=100;
a = x +""; //JS会自动隐性转换
//将string 变成 int
@ayuLiao
ayuLiao / js.js
Created January 19, 2019 09:09
javascript对数据与字典的操作
//操作字典
var dic = new Array();//通过申明一个Array来做一个字典
字典中项的遍历
for (var key in dic) {
console.log(key + ":" + dic[key]);
}
@ayuLiao
ayuLiao / DOMload.js
Created January 19, 2019 08:59
页面加载完后,执行ajax,需要使用jquery这个库,页面的DOM加载完后,直接执行,如果使用window.load需要等待页面中的图像也加载完成
var onLoginSuccess = function (data) {
console.log(data);
};
//页面中DOM结构加载完后,直接执行
$(function() {
var ajaxObj = {
type: 'GET',
url: 'http://127.0.0.1:8000/api/albumstyles', //URL上一定要带HTTP,不然报错
success: onLoginSuccess, //ajax成功,前端的回调函数
dataType: "json"
@ayuLiao
ayuLiao / gen_thumb_image.py
Created January 15, 2019 08:32
python生成缩略图
from PIL import Image as ImagePIL
def gen_thumb_image(path, width=0, height=0, filetype='JPEG'):
'''
生成缩略图
'''
width = min(1024, width)
height = min(1024, height)
img = ImagePIL.open(path)
if width and not height:
@ayuLiao
ayuLiao / inst_pip.py
Created January 10, 2019 10:04
使用豆瓣源安装python第三方库
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com django
@ayuLiao
ayuLiao / requirements.py
Created January 7, 2019 02:34
通过pip生成或使用requirements.txt
# 生成 requirements.txt 文件
pip gamepy27 > requirments.txt
# 安装 requirements.txt 中的依赖
pip install -r requirements.txt
@ayuLiao
ayuLiao / df.sh
Created January 3, 2019 01:59
Linux查看分区、磁盘空间大小
# 查看磁盘的使用情况以及文件系统被挂载的位置
df -lh
Filesystem 容量 已用 可用 已用% 挂载点
/dev/hda8 11G 6.0G 4.4G 58% /
# 列出机器中所有磁盘的个数,也能列出所有磁盘分区情况
fdisk -l
# 磁盘信息
Disk /dev/sda: 299.4 GB, 299439751168 bytes
@ayuLiao
ayuLiao / show_lib.py
Created December 20, 2018 12:21
查看当前python使用第三方库的路径
from distutils.sysconfig import get_python_lib
print(get_python_lib())